Jakub Lang
Jakub Lang

Reputation: 181

Woocommerce - Product variations in stock

I have question about Woocommerce product variations. When I have variable product with three parameters/variant. I need to make a SPECIAL VARIANT showed only if the first or second variant is in stock. When customer buy both variants, the SPECIAL must hide. SPECIAL variant can not be the only one visible for example:

VARIANT 1 - 1x in stock
VARIANT 2 - 1x in stock
VARIANT SPECIAL - in stock only if V1 or V2 is in stock

Customer buy V1:

VARIANT 1 - HIDE (out of stock)
VARIANT 2 - 1x in stock
VARIANT SPECIAL - in stock only if V1 or V2 is in stock

Another customer buy V2:

VARIANT 1 - HIDE (out of stock)
VARIANT 2 - HIDE (out of stock)
VARIANT SPECIAL - HIDE (both variants is out of stock)

IMAGE OF VARIANTS

I do not know if I explained well, sorry for my English.

Any solutions for this? Any hook, snippet or plugin?

I'll be glad for any advice, Jakob.

Upvotes: 0

Views: 485

Answers (1)

Syntax_Error
Syntax_Error

Reputation: 819

You are going to need the function is_in_stock and some if for each variations. Here is my example.

        if ($product_stock1=$variation_product->is_in_stock())
        {
        echo "Variacion 1 en Stock";
        }

        if ($product_stock2=$variation_product2->is_in_stock())
        {
        echo "Variacion 2 en Stock";
        }
        if (($product_stock1)||($product_stock2))
        {
        echo "Variacion 3 Visible";
        }

The code has been tested and is functional. The theme I use to test this code is Storefront. Depending on which page you are going to display this, it depends the hook.

Upvotes: 0

Related Questions