Last active
August 29, 2015 14:25
-
-
Save stuartduff/8e3b496b36d5b0507a2e to your computer and use it in GitHub Desktop.
This snippet will exclude the on sale products from the WooCommerce loop
This file contains 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
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