Forum

Thread tagged as: Question, Shop

Sold out variant

Is there a way to target a variant that has sold out in order to grey out the option in the select box/radio button? At the moment I have the main add to basket button removed when the main product has sold out, but no way of indicating an individual variant of that product is out of stock. At the moment it just wont add to the cart.

Rob Saunders

Rob Saunders 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Good question. Are you using the select box display or templating it yourself?

I was using the select box as described in the documentation but found that the product wouldn't add to the cart with that, so have changed to the radio buttons as per the docs. They work fine and add to cart correctly.

I'm also finding that if a product stock level is set to 'In Stock' then it will not add to the cart, changing the stock level to 'Unlimited' and it adds to the cart fine.

Drew McLellan

Drew McLellan 2638 points
Perch Support

What quantity of stock is set, regardless of status?

No quantity, just in stock...ah I guess it needs a quantity as well right!?

I can't work out the best way to display that to the end user...same as with the variants being out of stock. At the moment I have an if statement checking if the stock is set to "out of stock" but how to best combine that with the quantity being depleted?

<perch:if id="stock_status" value="3">
            <perch:if id="stock_level" value="0">
              <p class="out-of-stock"><span class="bold__big">Out of Stock</span> - <a href="mailto:info@inara-interiors.co.uk">Contact us</a> to check availability
              </p>
              <perch:else />
              <perch:input type="submit" value="Add to basket" class="product__submit" />
            </perch:if>
          </perch:if>

Basically I need an OR between those two if statements but I dont think thats allowed :)

Drew McLellan

Drew McLellan 2638 points
Perch Support

stock_level is the one you want to test for. That's going to change dynamically as items are ordered.

Thanks, any thoughts on the variants being out of stock? Also is it possible to remove the option of 'Unlimited' from the stock select box? Can't find where that is set and if unlimited is used it will still display out of stock.

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you're tracking stock on the variant (and not on the parent) then stock_level should be enough to tell if a variant is in stock or not.

It's not possible at the moment to customise the stock level statuses.

Hi Drew, did you get anywhere with the original question? Still wandering how to display if a variant is out of stock and make the select option greyed out or similar so the user cannot try to add it to the cart.

Cheers!

Drew McLellan

Drew McLellan 2638 points
Perch Support

It should be. Is it not?

No, if I set a variant to out of stock the radio button is still available to select...if you then add to cart it just jumps to the basket which is empty...so it is recognising the variant is out of stock but not displaying that to the user.

Drew McLellan

Drew McLellan 2638 points
Perch Support

And you're setting it to be out of stock using the quantity field? (not the status)

Yes setting it in both fields

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, that shouldn't be the case.

Anything I can do to fix it at my end?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't think so, I'm going to look into it.