Created
July 16, 2015 05:38
-
-
Save AchalJ/9e22bbeddbc7d758dc51 to your computer and use it in GitHub Desktop.
WooCommerce: Hide Out of Stock products from a category
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Term ID - 10 */ | |
| add_filter( 'pre_get_posts', 'hide_out_of_stock_from_cat' ); | |
| function hide_out_of_stock_from_cat( $query ) { | |
| if ( $query->is_tax( 'product_cat', 10 ) && $query->is_main_query() ) { | |
| $query->set( 'meta_query', array(array( | |
| 'key' => '_stock_status', | |
| 'value' => 'outofstock', | |
| 'compare' => 'NOT IN' | |
| ))); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What about multiple categories please?