This is a complex question and implementing this functionality requires very deep knowledge. I have came up with a hackish solution, that works in similar way, but has many limitations and should only be used if nobody comes up with a better idea.
If you have two sizes for all products and they’re in exact order as you’ve described, you can display a static message. It will be one of these messages, based on product variant quantities left:
XL size is out of stock but available for preorder
XL to 3XL size is out of stock but available for preorder
XL and XL to 3XL sizes are out of stock but available for preorder
To add this functionality you must have inventory tracking and selling when out of stock for your products enabled.
Go to Online Store → Themes → Customise
Select your product page template and add liquid block in Product information. Copy and paste following code:
{% if product.variants.first.inventory_quantity == 0 and product.variants.last.inventory_quantity > 0 %}
XL size is out of stock but available for preorder
{% elsif product.variants.first.inventory_quantity > 0 and product.variants.last.inventory_quantity == 0 %}
XL to 3XL size is out of stock but available for preorder
{% elsif product.variants.first.inventory_quantity == 0 and product.variants.last.inventory_quantity == 0 %}
XL and XL to 3XL sizes are out of stock but available for preorder
{% endif %}
Limitations:
- functionality breaks if there are more than 2 variants.
- functionality breaks if there are more than 2 sizes in the store.
- if there are products with just 1 variant you might need to create and adjust different product template for them.
- message is static and does not change dynamically depending on chosen variant.
Due to the limitations I strongly advise using this method only if you can’t find a better solution.
