Woocommerce Featured Product by category

user2768973 picture user2768973 · Sep 11, 2013 · Viewed 8.5k times · Source

I am looking for help (thank you) to edit the Woocommerce php widget for 'featured products'.

The file I think I need to edit is found:

wp-content/plugins/woocommerce/classes/widgets/class-wc-widget-featured-products.php

The problem: 1. Featured products currently display featured products from ALL categories.

The edit required: 1. To only display featured products within the current category being viewed.

So here is an example:

I have three categories (dog food, cat food, other stuff).

Each category has a category homepage:

> www.mysite.com/dog-food

> www.mysite.com/catfood

www.mysite.com/other-stuff

When I add a featured products to the 'dog-food' category, the featured product widget also includes featured cat-food products. Which is useless if the customer does not have a cat.

I would like featured products widget to display only products that are featured from the current category being viewed - So dog-food customers will only see dog-food featured products (not cat-food or other-things)

I (think) I need to add an arguement to the PHP file noted above. Here is the current code found within the file:

$query_args['meta_query'][] = array(
'key' => '_featured',
'value' => 'yes'
);

I have tried adding:

$query_args['meta_query'][] = array(
'key' => '_featured',
'value' => 'yes',
'product_cat' => 'current_category'
);

But this did not work.

Any help anyone could offer would be much appreciated.

Many thanks in advance.

Answer

anoop picture anoop · May 22, 2014

Use this wordpress plugin

https://wordpress.org/plugins/sp-woocommerce-featured-product-by-category/

In this plugin we have just changes the Featured product shortcode.

The default short code is : [featured_products per_page="12" columns="4"]

And change in this shortcode with the help of Featured product by categor plugin is : [featured_product_categories cats="CATEGORY_ID" per_cat="6" columns="3"]