• Resolved gkarmas

    (@gkarmas)


    Hey,

    first of all, amazing work!

    I can’t figure out a way to display the product’s brand name or thumbnail (just name is fine) within the single product page by using a shortcode.

    Any tips?

    Best, G.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter gkarmas

    (@gkarmas)

    I created a code snippet for myself. Although, it always sits above the element I place the shortcode. It becomes a parent of the element.

    
    if ( is_plugin_active( 'perfect-woocommerce-brands/main.php' ) ) {
      function product_brand_name_in_single_page_function() {
    
        global $product;
        $brands = wp_get_object_terms( $product->get_id(), 'pwb-brand' );
    
        ob_start();
        ?>
    
        <?php foreach( $brands as $brand ): ?>
    
          <?php
          $brand_id = $brand->term_id;
          $brand_name = $brand->name;
          $brand_link = get_term_link($brand_id);
          $brand_logo = get_term_meta( $brand->term_id, 'pwb_brand_image', true );
          $brand_logo = wp_get_attachment_image( $brand_logo, 'thumbnail' );
          ?>
    
          <div id="pwb_product-brand-name">
            <a href="<?php echo $brand_link;?>"><?php echo $brand_name;?></a>
            <?php if( !empty($brand->description) ) echo '<div>'.do_shortcode($brand->description).'</div>';?>
            <?php if( !empty($brand_logo) ) echo '<span>'.$brand_logo.'</span>';?>
          </div>
    
        <?php endforeach; ?>
    
        <?php
        echo ob_get_clean();
      }
      add_shortcode( 'product_brand_name_in_single_page', 'product_brand_name_in_single_page_function');
    }
    
    • This reply was modified 5 years, 10 months ago by gkarmas.
    • This reply was modified 5 years, 10 months ago by gkarmas.
    • This reply was modified 5 years, 10 months ago by gkarmas.
    Thread Starter gkarmas

    (@gkarmas)

    I uploaded an instructional screenshot of my issue: https://ibb.co/d0QmWqp

    Plugin Contributor titodevera

    (@titodevera)

    Hi gkarmas.

    Replace echo ob_get_clean(); by return ob_get_clean();.

    ??

    Thread Starter gkarmas

    (@gkarmas)

    Oooooh thank you so much @titodevera – you are a genius, I didn’t even see that ??

    • This reply was modified 5 years, 9 months ago by gkarmas.

    Hi, I’m looking for a way to use a shortcode to display the Brand link in a custom position on product pages, specifically in between the “Category” and “Tag” links just below the SKU. I am using the Flatsome theme.

    Can the code above be used to generate such a shortcode? Does the code snippet go in functions.php?

    Hi @saucemaniashop I want to do the same thing with the same theme, did you find a solution?

    No, sadly I have not found a solution. ??

    Unfortunately, none of the available brand link positions are suitable for me. I don’t understand why it cannot be displayed via a shortcode.

    Anonymous User 853254

    (@anonymized-853254)

    Hello

    I have installed the plugin with default settings. The brand name does not display on single product page at frontend. I am using Sober Theme.

    Are there any other instructions on how to make this work? Shortcodes?
    Thanks.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Display product brand on single product page via shortcode’ is closed to new replies.