product.selected_or_first_available_variant not returning variant thats in stock

Topic summary

Issue: A Shopify product page using Liquid assigns a variant with product.selected_or_first_available_variant but often returns a sold‑out variant despite other variants being in stock. This affects a shoe with multiple colors and sizes.

Context: Screenshots (central to understanding) show several sizes marked sold out, making it unclear which size the code resolves to.

Guidance provided:

  • The selected_or_first_available_variant respects a variant specified in the URL’s variant parameter. If a sold‑out variant is passed in the URL, it will be returned. Consider changing how variants are linked or preselected.
  • If no URL selection is intended, use product.first_available_variant instead and follow its in‑stock selection rules.
  • Improve UX to clarify which size is selected and guide customers toward in‑stock options, as multiple sold‑out sizes create ambiguity.

Outcome: No confirmed fix from the original poster. The recommended next steps are to verify/remove the URL variant parameter when inappropriate, switch to first_available_variant if desired behavior is to auto‑select an in‑stock option, and adjust the UI for clearer variant status and selection. The thread remains open/unsolved.

Summarized with AI on December 16. AI used: gpt-5.

Hey people,

Looking for a workaround to

{%- assign variant = variant | default: product.selected_or_first_available_variant -%}

I have a shoe which has multiple colors and sizes. Unfortunately this line keeps returning a variant that is sold out even though there are other variants that are still in stock.

Has anyone encountered this issue before and have a workaround?

Hi @jasonpxf see the docs https://shopify.dev/docs/api/liquid/objects/product#product-selected_or_first_available_variant

If the store uses variants that are selected in the URL variant parameter that should be respected and some other affordance should be used to get customers to select instock variants.

otherwise use first_available_variant and it’s rules https://shopify.dev/docs/api/liquid/objects/product#product-first_available_variant

Also take a look at the UX in the screenshot, multiple variants are sold out so there’s no way from the description to even know what size is even selected or returned by the code. (though it should be 7)