Last active
July 25, 2020 09:23
-
-
Save jameshwartlopez/03d00a0b3963fca709978a9722e72e54 to your computer and use it in GitHub Desktop.
Exclude featured product in the main product loop or remove any featured product from regular archive loop. See https://jameshwartlopez.com/plugin/remove-any-product-that-is-featured-from-regular-display-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
<?php | |
/** | |
* Add in your themes functions.php | |
* Exclude featured product in the main product loop | |
*/ | |
add_action( 'woocommerce_product_query', function ($query) { | |
if ( ! is_admin() && $query->is_main_query() ) { | |
// Not a query for an admin page. | |
// It's the main query for a front end page of your site. | |
if ( is_product_category() ) { | |
// It's the main query for a product category archive. | |
$tax_query = (array) $query->get( 'tax_query' ); | |
// Tax query to exclude featured product | |
$tax_query[] = array( | |
'taxonomy' => 'product_visibility', | |
'field' => 'name', | |
'terms' => 'featured', | |
'operator' => 'NOT IN', | |
); | |
$query->set( 'tax_query', $tax_query ); | |
} | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment