-1

This method was working at one stage, but lost track when it has started to not filter after sets of changes over time. Hopefully the answer stares at someone in the face. In my child theme functions.php, I have:

function shop_store_filter() {
  if (is_shop() || is_product_category() || is_product()) {
    add_filter( 'woocommerce_product_query_meta_query', 'storeFilter', 9 );
  }
}
function storeFilter($meta_query) {
  $meta_query[] = array(
    'post_type'      => 'product',
    'meta_query'     => array(
      array(
        'key'     => '_product_attributes',
        'value'   => $_GET["sid"],
        'compare' => 'LIKE',
        'type'    => 'product'
      )
    )
  );
  return $meta_query;
}
add_action( 'wp', 'shop_store_filter' );

I'm getting an empty $meta_query array for where this filter is called from class-wc-query.php though, so it's like it is not registering as above. I've confirmed that the is_shop() is true.

Any suggestions?

EDIT

I want to emphasize two things from the comments below, which may have gone misunderstood:

1) I have said that the advice example was working. It is not a taxonomy, the value I'm trying to filter on is a store ID, so there is not meant to have a definitive set of possible values like colours. Also refer to this example:

Woocommerce: Show products filtered by attribute

2) The query aside, the bigger issue is that the function it is wrapped in does not seem to be triggered by the woocommerce_product_query_meta_query filter. Strange, this is where I am stuck.

Jester
  • 367
  • 1
  • 3
  • 13
  • you have removed the changes as sets of changes over time. And after clear the cache. Again refresh the page and check it. – Priyanka Modi Sep 07 '18 at 05:23
  • To be honest, I'm just not sure at what point it broke, and if it's on behalf of a plugin we've added, or what. Is there a way to verify that the function calling the tag (`class-wc-query.php`->`woocommerce_product_query_meta_query`) had successfully executed the function `storeFilter`? – Jester Sep 07 '18 at 06:00

1 Answers1

-1

Fixed - the query was still fine. I don't remember why we had the check of is_post()... but I moved add_filter( 'woocommerce_product_query_meta_query', 'storeFilter', 1 ); back out of the function to be executed on its own and it was OK.

Jester
  • 367
  • 1
  • 3
  • 13