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.