Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter montebianco

    (@montebianco)

    1. Didn’t see where the setting page was: I found the logo position under the woocommerce > settings > brands and set to before title on single product page.

    Thread Starter montebianco

    (@montebianco)

    2. Added following to functions.php

    function pwb_show_brands_in_loop(){
    	global $product;
    	$product_id = $product->id;
    	$product_brands =  wp_get_post_terms($product_id, 'pwb-brand');
    	if(!empty($product_brands)){
    		echo '<div class="brand">';
    		foreach ($product_brands as $brand) {
    			echo '<span>'.$brand->name.'</span>';
    		}
    		echo '</div>';
    	}
    }
    add_action('woocommerce_before_shop_loop_item_title', 'pwb_show_brands_in_loop');

    How can i link the echo ‘<span>’.$brand->name.'</span>’; with an a href= of the brand link?

    Plugin Contributor titodevera

    (@titodevera)

    Awesome montebianco! It works like a charm!

    How can i link the echo ‘<span>’.$brand->name.'</span>’; with an a href= of the brand link?

    I think that it is not posible (using the suggested hook). The woocommerce_before_shop_loop_item_title hook inserts the code into a link pointing to the product. Obviously it is not posible to include a link inside another link.

    But… you can use other hook that injects the code outside the product’s link…

    function pwb_show_brands_in_loop(){
    	global $product;
    	$product_id = $product->id;
    	$product_brands =  wp_get_post_terms($product_id, 'pwb-brand');
    	if(!empty($product_brands)){
    		echo '<div class="custom-loop-brands">';
    		foreach ($product_brands as $brand) {
    			echo '<a href="'.get_term_link($brand->term_id).'">'.$brand->name.'</a>';
    		}
    		echo '</div>';
    	}
    }
    add_action('woocommerce_after_shop_loop_item', 'pwb_show_brands_in_loop',1);

    ??

    That’s was looking 4!

    Plugin Contributor titodevera

    (@titodevera)

    Resolved ??

    olegl

    (@olarionov)

    Hi

    It is excellent thread. I have add the code below to functions.php and it does place Brand name between picture box and product tile in category/catalog view.

    The issue is that the Brand name font / color /stile is the same as product title and it has link to Brands page, so it is very easy for a user to click the brand link to jump away on to brands page.
    1. How can I change the font stile / color for a brand in category view?
    2. Can I remove the actual link from the brand name in the category view so the brand become just a text label?

    Code I used:

    /*** Brands in Catalog**/
    function pwb_show_brands_in_loop(){
    	global $product;
    	$product_id = $product->id;
    	$product_brands =  wp_get_post_terms($product_id, 'pwb-brand');
    	if(!empty($product_brands)){
    		echo '<div class="custom-loop-brands">';
    		foreach ($product_brands as $brand) {
    			echo '<a>term_id).'">'.$brand->name.'</a>';
    		}
    		echo '</div>';
    	}
    }
    add_action('woocommerce_before_shop_loop_item_title', 'pwb_show_brands_in_loop',1);
    
    • This reply was modified 8 years ago by olegl.
    • This reply was modified 8 years ago by olegl.
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Display position on product page and shop pages’ is closed to new replies.