WPITECHWPITECH

    Subscribe to Updates

    Get Latest WordPress Tutorials and Updates

    What's Hot

    12 Best Ecommerce Software in 2021 & in the Future

    July 31, 2021

    Why Is My Canon Printer Not Printing Properly?

    July 31, 2021

    5 Best Google Analytics Plugins

    May 28, 2021
    Facebook Twitter Instagram
    Facebook Twitter Instagram
    WPITECH WPITECH
    Subscribe
    • Home
    • Tutorials
      • WordPress Tutorials
      • WordPress Plugin
      • WordPress Themes
      • WooCommerce
      • Ecommerce
      • PHP
    • Hosting
    • Deals
      • Hosting Deals
    • SEO TOOLS
      • Bulk Url Checker
      • Structured Data
      • Google Cache
      • Hyperlink Generator
      • Free URL Checker
    • Marketing
      • SEO
      • Advertising
    • Reviews
    • Write for Us
    • About Us
    WPITECHWPITECH
    Home ยป Show Category in WooCommerce Product Loop
    WooCommerce

    Show Category in WooCommerce Product Loop

    WPITECHBy WPITECHApril 8, 2019No Comments1 Min Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Display-category-name-in-woocommerce-product-loop
    Share
    Facebook Twitter LinkedIn Pinterest Email

    An online store in WooCommerce, show the name of the category in the product loop (in the last products of the home page and the category page), next to the name and the price.

    I think there are some templates that already foresee it, but that was not the case, so I had to look for some function that would add it.

    I leave it to you in case someone needs the same thing and this way the search is saved ๐Ÿ˜‰

     remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
     add_action( 'woocommerce_shop_loop_item_title', 'DPW_woo_loop_product_title', 10 );
    
    function DPW_woo_loop_product_title() {
    
    $terms = get_the_terms( $post->ID, 'product_cat' );
     if ( $terms && ! is_wp_error( $terms ) ) :
     //only displayed if the product has at least one category
     $cat_links = array();
     foreach ( $terms as $term ) {
     $cat_links[] = $term->name;
     }
     $on_cat = join( " ", $cat_links );
     ?>
    <?php endif;
     echo '' . get_the_title() . '';
     }

    What it does is replace the standard WooCommerce template to show the product title in the loop and replace it with a custom one that includes the array of product categories, so if it belongs to more than one, all will be displayed.

    show category in WooCommerce product loop WooCommerce product loop
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    WPITECH

    Related Posts

    5 Best WooCommerce Affiliate Plugins

    January 3, 2020

    How to Customize Add to Cart Button in WooCommerce

    October 21, 2019

    How to Customize WooCommerce Product Variations

    October 13, 2019
    Add A Comment

    Leave A Reply Cancel Reply

    Recent Posts
    • 12 Best Ecommerce Software in 2021 & in the Future
    • Why Is My Canon Printer Not Printing Properly?
    • 5 Best Google Analytics Plugins
    • 12 Best Email List Building Tools in 2021
    • 9 Amazing Benefits of Using WordPress for Your Projects
    Recent Comments
    • 20+ Top Ecommerce Marketing Agencies To Hire for 2020 on Conversion Rate Optimization Tips to Improve Conversions and Increase Revenue
    • Hottest B2B Content Marketing Trends and Statistics in 2019 on The Ultimate Guide to Broken Link Building 2020
    • Digital Chetan on SEO 2020 Google RankBrain Algorithm GUIDE
    Editors Picks
    Top Reviews
    Advertisement
    Demo
    Facebook Twitter Instagram Pinterest Vimeo YouTube
    • Home
    © 2022 All rights reserved

    Type above and press Enter to search. Press Esc to cancel.