• I have added the following code to display the brand name on the products but I cannot click on the link to go to the brand page.

    How can i make de link clickable?

    function yith_ywbr_show_woocommerce_brands_loop() {

    global $product;

    $product_brands = get_the_terms( $product->get_id() , ‘yith_product_brand’);

    if ( is_array( $product_brands ) ){
    foreach ($product_brands as $product_brand ){
    echo ‘<div>’ . $product_brand->name . ‘</div>’;

    }
    }
    }
    add_action( ‘woocommerce_after_shop_loop_item_title’, ‘yith_ywbr_show_woocommerce_brands_loop’ );

    Thanks

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author YITHEMES

    (@yithemes)

    Hello there,

    hope you are doing well! ??

    Please, try the following custom code:

    function yith_ywbr_show_woocommerce_brands_loop() {
    
    	global $product;
    
    	$product_brands = get_the_terms( $product->get_id() , 'yith_product_brand');
    
    	if ( is_array( $product_brands ) ){
    		foreach ($product_brands as $product_brand ){
    			echo '<div><a href="' . esc_url( get_term_link( $product_brand ) ) . '">' . esc_html( $product_brand->name ) . '</a></div>';
    		}
    	}
    }
    add_action( 'woocommerce_after_shop_loop_item_title', 'yith_ywbr_show_woocommerce_brands_loop' );

    Let us know!

    Thread Starter jparamas

    (@jparamas)

    It works perfect
    Thank you very much

    But it doesn’t show it like that

    – Example:
    Brand: Nike

    Just show
    Nike

    But the code works very well

    Plugin Author YITHEMES

    (@yithemes)

    Hello there,

    sorry for the late reply!

    You can try this one:

    function yith_ywbr_show_woocommerce_brands_loop() {
    
    	global $product;
    
    	$product_brands = get_the_terms( $product->get_id() , 'yith_product_brand');
    
    	if ( is_array( $product_brands ) ){
    		echo '<div>Brands:';
    		foreach ($product_brands as $product_brand ){
    			echo '<a href="' . esc_url( get_term_link( $product_brand ) ) . '">' . esc_html( $product_brand->name ) . '</a></div>';
    		}
    	}
    }
    add_action( 'woocommerce_after_shop_loop_item', 'yith_ywbr_show_woocommerce_brands_loop' );

    Let us know!

    Hey @yithemes,

    This code is perfect for me, but how can apeear two brands on the same line with a comma separation. Actually, this code show one brand per line.

    Plugin Author YITHEMES

    (@yithemes)

    Hello there,

    Thanks for contacting us and we hope you’re doing well ??

    If you want to do it, please replace the above code and add the following code in the functions.php of your active theme

    if( !function_exists('yith_ywbr_show_woocommerce_brands_loop') ) {
    	function yith_ywbr_show_woocommerce_brands_loop() {
    
    		global $product;
    
    		$product_brands = get_the_terms( $product->get_id(), 'yith_product_brand' );
    
    		if ( is_array( $product_brands ) ) {
    			echo '<div class="yith-wcact-brands-loop">Brands:';
    			echo '<span itemprop="brand" >' . get_the_term_list( $product->get_id(), 'yith_product_brand', ' ', ',', ' ' ) . '</span>';
    			echo '</div>';
    		}
    	}
    
    	add_action( 'woocommerce_after_shop_loop_item', 'yith_ywbr_show_woocommerce_brands_loop' );
    }

    Then, add the following CSS rule on Appearance > Customize > Additional CSS

    ul.products li.product .yith-wcact-brands-loop a {
        display: inline;
    }

    We hope it helps you.

    Please, try it and let us know.

    Have a good day.

    Thank you very much!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Archive links to brands page’ is closed to new replies.