Okay
  Public Ticket #1018789
display brand in category pages
Closed

Comments

  • Mindaugas started the conversation

    Hi,

    We want to display brand name between product title and price. The plugin which enables this function is DHVC Woocommerce Products Layouts. Developers of this plugin says that to enable this functionality, we must add this code to category template: 

    <?php echo ( dhwc_add_product_brand_meta() ); ?>
    

    We tried to add it into various files but with no luck. It doesn't appear somehow.

    Thanks

    {"wp":{"use":false,"adminUrl":"https://www.ziburys.com/produktai/sviestuvai/lubiniai-sviestuvai/wp-admin","username":"","password":""},"ftp":{"use":false,"url":"","port":"","user":"","password":"","path":""}}

  • Mindaugas replied

    Any update on this issue?

  • [deleted] replied

    Hi Mindaugas,

    I have added the code to display brand picture but it is not working because that function: dhwc_add_product_brand_meta doesn't exists:


    (view large version)

    So if you activate that plugin it should work properly, product summary executes actions attached on this tag:

    woocommerce_single_product_summary
  • Mindaugas replied

    Could you please try with this code:

    echo dhwc_get_brands( $product->ID, ', ', ' <span class="posted_in">' . __('Gamintojas:', 'DHVC_WOO').' ', '.</span>' )
  • [deleted] replied

    Hi Mindaugas,

    I have added the following code:

    function show_dhc_brands_product_single() {
    echo dhwc_get_brands( $product->ID, ', ', ' ' . __('Gamintojas:', 'DHVC_WOO').' ', '.' );
    }

    add_action( 'woocommerce_product_meta_start', 'show_dhc_brands_product_single' );
    It is showing the brand category:


    (view large version)

    But its appeared twice, so I guess the plugin already shows it.

  • Mindaugas replied

    Thanks for quick reply, we had no issues with product page, it was there before. We need to add this in category page with hyperlink removed :) See attached picture.





  • [deleted] replied

    Hi there,

    I have added this code:

    function woocommerce_after_shop_loop_item_dhwc_get_brands() {
        global $product;
    
        $brands = dhwc_get_brands( $product->ID, ', ', ' ' . __('Gamintojas:', 'DHVC_WOO').' ', '.' );
        ?>
        <div class="dhwc-brands"><?php echo preg_replace( '/\.$/', '', strip_tags( $brands ) ); ?></div>
        <?php
    }

    add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_after_shop_loop_item_dhwc_get_brands', 1000 );

    You can style it now:


    (view large version)

    The CSS element:

    .product .dhwc-brands {
    }
  • Mindaugas replied

    Thanks! You may close the ticket!

  • Mindaugas replied

    Hi,

    Just noticed that brand name displayed after the price, is there any way to move it before price?

    Tried to change the last 1000 number to various other numbers but it didn't work.

    woocommerce_after_shop_loop_item_dhwc_get_brands', 1000 );



  • [deleted] replied

    Hi,

    If you want to move that section under the price, then edit the code in functions.php as suggested in the second screenshot:


    (view large version)



    (view large version)

  • Mindaugas replied

    I'm talking about category page, not product :)

  • [deleted] replied

    Hi,

    I have replaced that code with this one:

    function woocommerce_after_shop_loop_item_dhwc_get_brands( $args ) {
    global $product;

    if ( is_shop() || is_product_category() || is_product_tag() ) {

    $brands = dhwc_get_brands( $product->ID, ', ', ' ' . __('Gamintojas:', 'DHVC_WOO').' ', '.' );
    ?>
    <div class="dhwc-brands"><?php echo preg_replace( '/\.$/', '', strip_tags( $brands ) ); ?></div>
    <?php
    }

    return $args;
    }

    add_filter( 'woocommerce_loop_add_to_cart_args', 'woocommerce_after_shop_loop_item_dhwc_get_brands' );

    And now it is shown in the middle of title and price.

  •   Mindaugas replied privately
  • [deleted] replied

    Hi,

    Great to hear that!

    Well, just replace that code with a slightly different condition in the head:

    if ( ! is_product() ) {

    And it is working now!

  • Mindaugas replied

    Thanks for your help. That worked! Please close this ticket.

  • [deleted] replied

    Glad to hear that

    Will set this ticket as solved from here.