Joel Jerushan / Web Developer from Batticaloa Sri Lanka

Call +94766881010, Email boomerang@joel.lk

Perfect WooCommerce Brands – WordPress Plugin – Custom Term Loop

Posted on: June 4th, 2017 by Joel Jerushan

After Citylagoon Guest House a client came up with a project (online store) have completed almost 80% of e’m. but before finalizing and the ending Client asked me to finish up the application but he need a slider one particular page that will show brands and brands page will show all products listed by brand.

After few hours of Research about WordPress Woocommerce Brand listing i found a plugin called Perfect WooCommerce Brands Really useful plugin that i ever got. after found this useful plugin i gotta problem with listing all Custom Woocommerce Term called Brand. after wasting 4 hours 😀 (seriously) i created a filter for wordpress like following.

<?php $terms = get_terms('pwb-brand'); foreach ( $terms as $term ) { 
   $brand_link = get_term_link($term->term_taxonomy_id);
   $thumbnail_id = get_term_meta( $term->term_taxonomy_id, 'pwb_brand_image', true );
   $image = wp_get_attachment_url( $thumbnail_id );
?>
  
<li>
    <a href="<?php echo $brand_link; ?>">
        <img src="<?php echo $image; ?>" />
    </a>
</li>
<?php } ?>

Code Explained
// get perfect woocommerce brand term in to var
$terms = get_terms('pwb-brand'); 
//loop to list all created brand terms 
foreach ( $terms as $term ) { 
   // brand link for term url 
   $brand_link = get_term_link($term->term_taxonomy_id);

   //get term single id and set it to brand image ('pwb_brand_image')
   $thumbnail_id = get_term_meta( $term->term_taxonomy_id, 'pwb_brand_image', true );

   //normal wordpress image attachment url by id 
   $image = wp_get_attachment_url( $thumbnail_id );
//loop it wherever you want that's it 
<?php echo $brand_link; ?>

i’m here to help if you struck somewhere here 😀

Call 94766881010 or email boomerang@joel.lk

 

Tags: , , , , , , , , , , , , , , ,