Skip to content

Instantly share code, notes, and snippets.

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 jameshwartlopez/03d00a0b3963fca709978a9722e72e54 to your computer and use it in GitHub Desktop.
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/
<?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