Advertisement
borkolivic

Exclude products with specific tag from shop loop

Feb 1st, 2020
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.47 KB | None | 0 0
  1. function exclude_specific_tag_from_shop_loop( $q ) {
  2.     if (is_shop()){
  3.         $tax_query = (array) $q->get( 'tax_query' );
  4.         $tax_query[] = array(
  5.             'taxonomy' => 'product_tag',
  6.             'field' => 'slug',
  7.             'terms' => array( 'cross' ), // your tag slug here
  8.             'operator' => 'NOT IN'
  9.         );
  10.         $q->set( 'tax_query', $tax_query );
  11.     }
  12. }
  13. add_action( 'woocommerce_product_query', 'exclude_specific_tag_from_shop_loop' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement