Home Forums Basel support forum Show Attribute text (title) instead of image

Show Attribute text (title) instead of image

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #55598

    antonchaik88
    Participant

    If I use brands and choose to “Show attribute on product page” it will show the logo I assigned to it. I want it to show the brand name, or title, instead. How can I do that?

    #55638

    Eric Watson
    Participant

    Hello,

    Could you explain in more detail or provide a screenshot, where exactly do you want to change the image to the title?

    Kind Regards
    XTemos Studio

    #55756

    antonchaik88
    Participant

    I really don’t know how to be any more descriptive. Your theme offers brands. When brands are enabled, the brand logo shows up on product pages. I want the brand AND title to show up, not just the brand.

    Theme Settings-> Shop -> Brands

    #55762

    Eric Watson
    Participant

    Hello,

    Try to add the following PHP code snippet to the child theme functions.php file to do this

    	function basel_product_brand() {
    		global $product;
    		$attr = basel_get_opt( 'brands_attribute' );
    		if( ! $attr || ! basel_get_opt( 'product_page_brand' ) ) return;
    
    		$attributes = $product->get_attributes();
    
    		if( ! isset( $attributes[ $attr ] ) || empty( $attributes[ $attr ] ) ) return;
    
    		$brands = wc_get_product_terms( $product->get_id(), $attr, array( 'fields' => 'all' ) );
    
    		if( empty( $brands ) ) return;
    
    		if ( defined( 'SHOP_IS_ON_FRONT' ) ) {
    			$link = home_url();
    		} else {
    			$link = get_post_type_archive_link( 'product' );
    		}
    
    		echo '<div class="basel-product-brands">';
    
    		foreach ($brands as $brand) {
    			$image = basel_tax_data( $brand->taxonomy, $brand->term_id, 'image' );
    			$filter_name    = 'filter_' . sanitize_title( str_replace( 'pa_', '', $attr ) );
    
    			$attr_link = add_query_arg( $filter_name, $brand->slug, $link );
    
    			
    				echo '<div class="basel-product-brand">';
    					echo '<a href="' . esc_url( $attr_link ) . '">' . esc_html( $brand->name ) . '</a>';
    				echo '</div>';
    			
    
    		}
    
    		echo '</div>';
    
    	}

    Kind Regards
    XTemos Studio

    #55941

    antonchaik88
    Participant

    Hello,
    I see this puts the title where the product brand logo used to be, which is good.
    However, I would also like to show the it on each shop product page, not single product page.

    This is inside the “product-labels labels-rectangular” div, as an added span element I suppose.

    #55957

    Eric Watson
    Participant

    Hello,

    Try to add the following PHP code snippet to the child theme functions.php file to do this

    	function basel_get_product_attributes_label(){
    		global $product;
    		$attributes = $product->get_attributes();
    		$output = array();
    		foreach ( $attributes as $attribute ) {
    			if ( !isset( $attribute['name'] ) ) continue;
    		    $show_attr_on_product = basel_wc_get_attribute_term( $attribute['name'], 'show_on_product' );
    			if ( $show_attr_on_product == 'on' ) {
    				$terms = wc_get_product_terms( $product->get_id(), $attribute['name'], array( 'fields' => 'all' ) );
    				foreach ( $terms as $term ) {
    					$content = esc_attr( $term->name );
    					$classes = 'label-term-' . $term->slug;
    					$classes .= ' label-attribute-' . $attribute['name'];
    					
    					$output[] = '<span class="attribute-label product-label ' . esc_attr( $classes ) . '">'. $content .'</span>';
    				}
    			}
    		}
    		return $output;
    	}

    Kind Regards
    XTemos Studio

    #56831

    antonchaik88
    Participant

    That worked thank you!

    #56880

    You are welcome! If you have any questions feel free to contact us.

    Best Regards

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Show Attribute text (title) instead of image’ is closed to new replies.