Skip to content

Instantly share code, notes, and snippets.

@stuartduff
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuartduff/8e3b496b36d5b0507a2e to your computer and use it in GitHub Desktop.
Save stuartduff/8e3b496b36d5b0507a2e to your computer and use it in GitHub Desktop.
This snippet will exclude the on sale products from the WooCommerce loop
function custom_exclude_on_sale_products_from_query( $q ){
if ( $q->is_search() ) return;
if ( ! $q->is_main_query() ) return;
if ( ! $q->is_post_type_archive() ) return;
if ( ! is_admin() ) {
$product_ids_on_sale = wc_get_product_ids_on_sale();
$q->set( 'post__not_in', (array) $product_ids_on_sale );
}
}
add_action( 'woocommerce_product_query', 'custom_exclude_on_sale_products_from_query' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment