Skip to content

Instantly share code, notes, and snippets.

@AchalJ
Created July 16, 2015 05:38
Show Gist options
  • Select an option

  • Save AchalJ/9e22bbeddbc7d758dc51 to your computer and use it in GitHub Desktop.

Select an option

Save AchalJ/9e22bbeddbc7d758dc51 to your computer and use it in GitHub Desktop.
WooCommerce: Hide Out of Stock products from a category
/* 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'
)));
}
}
@thieryy2018

Copy link
Copy Markdown

What about multiple categories please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment