PHPackages                             codelight/woocommerce-product-variation-stock-cache - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. codelight/woocommerce-product-variation-stock-cache

ActivePackage[Caching](/categories/caching)

codelight/woocommerce-product-variation-stock-cache
===================================================

v1.0(7y ago)17PHPPHP &gt;=7.0.0

Since Mar 6Pushed 7y ago2 watchersCompare

[ Source](https://github.com/codelight-eu/woocommerce-product-variation-stock-cache)[ Packagist](https://packagist.org/packages/codelight/woocommerce-product-variation-stock-cache)[ RSS](/packages/codelight-woocommerce-product-variation-stock-cache/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (2)Used By (0)

WooCommerce Product Variation Stock Cache
=========================================

[](#woocommerce-product-variation-stock-cache)

This library adds a way to filter variable products by attributes *and* stock status.

WooCommerce currently doesn't have a way of querying products by attribute and displaying it only if a variation with the given attribute is in stock. For details, [see the github issue](https://github.com/woocommerce/woocommerce/issues/20689). This functionality is scheduled to be released in v4.0, which is scheduled to be released somewhere in 2019, but no certain information is available yet.

Until then, you can use this library as a relatively simple workaround that won't affect performance much.

How it works
------------

[](#how-it-works)

The library keeps track of each variation's stock status in the parent product's post meta.

Let's say you have an attribute "Size" with the following values: "S", "M", "L". The library stores the stock statuses in the parent post meta like this:

```
'_codelight_stock_pa_size:s' => 'instock'
'_codelight_stock_pa_size:m' => 'instock'
'_codelight_stock_pa_size:l' => 'instock'

```

This allows you to use simple meta queries to fetch only those variable parent products that have a variation with a specific attribute in stock.

Installation
------------

[](#installation)

`composer require codelight/woocommerce-product-variation-stock-cache`

The library is initialized automatically and will start keeping track of stock status changes. To generate cache for existing products, see below.

Usage
-----

[](#usage)

In your WP\_Query for retrieving the products, use the following meta query:

```
