Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using WooCommerce on my Wordpress site, and have a widget in the sidebar showing all product categories. It's setup to hide empty categories, and that works well. However, it still shows categories that contain only products that are out of stock - that I would like to change.

Technical explanation: WooCommerce products are a custom post type (product), the product categories are a custom taxonomy (product_cat), and the stock count is a custom field on the products (_stock). The WooCommerce Product Categories widget shows them using wp_list_categories(). I have tried digging into a code to look for some filter call that I could hook onto, but failed to find one.

Is there a good way of doing this without modifying core or WooCommerce code? Maybe a hook/filter somewhere that I missed that would allow to check the custom field value?

share|improve this question

1 Answer

If you go to WooCommerce => Settings and select the 'Inventory' tab you'll see an option to 'Hide out of stock items from the catalog'. If you enable this option then out of stock items won't be displayed and if a category doesn't contain any sellable (out of stock or no price) items it will be hidden as well.

Update

Ok I read 'widget' and totally ignored it in my answer.

The WooCommerce Product Categories widget doesn't support filtering the products/categories as far as I know. So no hook or filter that I'm aware of.

But you could easily copy the single file and modify it as a stand alone widget that wouldn't be over written by a WooCommerce upgrade.

Hope that helps.

share|improve this answer
The option is checked. The out of stock items are not shown on shop pages, but they still count into category product numbers, and categories only containing out-of-stock items are still shown in the widget. – olex Dec 5 '12 at 8:50
Zoned out on the 'Widget'. See my updates in the answer. – Stephen Dec 5 '12 at 14:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.