All my products are variable, all of them have 4 variations, one for each region.
Users can select which of the 4 regions they want to see prices for when browsing.
The issue is that for some products, one or more variations/regions aren't enabled or out of stock so users end up seeing "out of stock" products while browsing.
I want to filter/hide products that don't have the variation type they have selected, site-wide (search included).
The selected variation type the user clicked is accessible in the session cookie. I think this filter might be a good start:
add_filter( 'woocommerce_product_query_meta_query', 'shop_only_available_products', 10, 2 );
so if $_COOKIE['region'] not in [list of variations for product] then -> hide
| Product 1 |
|---|
| Variant 1 (NA) - IN STOCK |
| Variant 2 (EU) - IN STOCK |
| Variant 3 (ASIA) - OUT OF STOCK |
| Variant 4 (AFR) - IN STOCK |
User has selected to browse by ASIA, so I want to hide this product because ASIA is out of stock. It has to account for what the user has selected.