WooCommerce add class name in the list

Currently, I am trying to customise the override WooCommerce.php file. Now, in this file,

<section id="content woocommerce" class="grid-block woocommerce">
<ul id="products" class="subcategory-products products">
<?php woocommerce_content(); ?>
</ul>
</section>

The output likes:

Read More
<li class="post-15 product type-product status-publish hentry first instock">
    <a href="http://shop.bbpixelz.dk/product/i-phone-ai-template/">
        <img width="150" height="150" src="http://shop.bbpixelz.dk/wp-content/uploads/2014/01/iphone-ai-template-150x150.png" class="attachment-shop_catalog wp-post-image" alt="iphone-ai-template">
        <h3>I-Phone Vector Template</h3>
    <span class="price"><span class="amount">$2</span></span>
    </a>
    <a href="/?add-to-cart=15" rel="nofollow" data-product_id="15" data-product_sku="ai-iphone" class="add_to_cart_button button product_type_simple">Add to cart</a>
</li>

What I am trying to do is to change the class name, currently the class name is post-15 product .... I would like to change the class name to product category.

Could someone help me?

Related posts

1 comment

  1. There is no particular hook available to deal with classes in products list.
    Therefore, we need to edit, “content-product.php” present in, “template” folder of “woocommerce” plugin.

    We can add following code:

    $product_id = get_the_ID();
    $result = wp_get_post_terms($product_id,'product_cat');
    
        if(!empty($result)){
    
            $term = '';
    
            foreach($result as $single_result)
            {
                $term .= ' ' . $single_result->slug;
            }
    
            $classes[] = $term;
        }
    

    after,

    $classes = array(); 
    

    statement.

    This will result in the following output:

    <ul class="products">
    <li class="post-246 product type-product status-publish hentry general first sale instock">
    <li class="post-33 product type-product status-publish hentry sale instock">
    <li class="post-244 product type-product status-publish hentry general special sale instock">
    </ul>
    

    where, “General” and “Special” are categories.

    Here I am fetching, product categories slugs and appending it to products class.

Comments are closed.