How can I create a custom function to manage stock at the individual attribute level?
For example
Product: t-shirt signed by me
- Attribute 1: Size – small | medium | large
- Attribute 2: Marker Color – blue | red | black
In cases like these, you’d want to manage stock by attribute 1 only. It makes no sense to manage stock by attribute 2 also.
What I’ve Tried
Since I’m just beginning with custom WordPress functions, I don’t know where to start. It seems that a custom stock reduction function that filters by SKU could work, but I’ve searched and can’t find any examples to work from.
Note: My actual use case for this is classes offered on different days with different payment options through WooCommerce Subscriptions:
Product: Learning Seminar
- Attribute 1: Class Day – Mon at 1 p.m. | Wed at 10 a.m.
- Attribute 2: Payment Options – Single Payment | 2 Payments | 4 Payments
I know this is a super old question, but I’ve had several clients ask for this type of attribute-based stock management, so I ended up developing a plugin for it: Attribute Stock for WooCommerce
The idea is that you can set stock directly on attribute terms which will get deducted appropriately when matching products are purchased.
For example: You can set your stock on each of the
Size
attribute terms and disable stock management for the product/variations so that stock is only managed at the attribute level.