Show out-of-stock variants in your theme
How to show sold-out product variants in your Shoporama theme, so customers can see your full range and sign up for back-in-stock notifications.
If you have a product profile with, for example, six sizes, but only three are in stock, Shoporama shows only the three available ones by default. You can customize your theme so all product variants are shown, including those that are out of stock, giving the customer a complete overview of your range.
Default behavior
By default, Shoporama only shows variants that are in stock. This prevents the customer from choosing a size or color that cannot be delivered anyway. That works well for the vast majority of stores, but if you sell a collection where individual sizes often sell out, it can be an advantage to show all variants and simply mark the ones that are not available right now.
The right methods in the theme
On a SafeProduct object, there are two methods you can call in your Smarty template:
- $product->getInStockVariants() returns only variants that are in stock.
- $product->getStockVariants($only_in_stock, $hide_stock) returns all variants. Set the first parameter to false to include both out-of-stock and available variants.
Both methods return an array of rows (not variant objects). Each row is an associative array with the following keys:
- attr_name, the name of the attribute (for example "Size")
- attr_tag, the attribute's tag (a code-friendly name, for example "size")
- name, the name of the variant value (for example "M" or "Red")
- cnt, the quantity in stock (0 if sold out, null if you have chosen to hide the stock quantity)
- attribute_id and attribute_value_id, IDs you use when the variant is added to the cart
- weight, the sort order
- price and sale_price, any variant-specific price
Show all variants in the theme
Switch to getStockVariants(false) in your product template. Example as a dropdown:
<select name="attribute[]">
<{foreach $product->getStockVariants(false) as $variant}>
<option value="<{$variant.attribute_value_id}>"
<{if $variant.cnt <= 0}>disabled<{/if}>>
<{$variant.name}><{if $variant.cnt <= 0}> (sold out)<{/if}>
</option>
<{/foreach}>
</select>
Example as clickable buttons with visual marking of out-of-stock options:
<{foreach $product->getStockVariants(false) as $variant}>
<button type="button"
data-attribute-id="<{$variant.attribute_id}>"
data-attribute-value-id="<{$variant.attribute_value_id}>"
class="variant-btn <{if $variant.cnt <= 0}>is-sold-out<{/if}>"
<{if $variant.cnt <= 0}>disabled<{/if}>>
<{$variant.name}>
</button>
<{/foreach}>
Styling out-of-stock variants
- Add the disabled attribute to out-of-stock options so they cannot be selected.
- Mark them visually with a CSS class, for example a muted color, a strikethrough, or a diagonal stripe.
- Show the text (sold out) after the variant name so it is clear to the customer.
Hide the stock quantity
If you do not want to reveal exactly how many are in stock (for example "only 2 left"), you can set the second parameter to true:
<{foreach $product->getStockVariants(false, true) as $variant}>
...
<{/foreach}>
Then $variant.cnt will be null on all variants, including those that are sold out. This means you cannot use cnt to tell whether a variant is sold out when you hide the stock quantity.
Combine with back-in-stock notifications
For out-of-stock variants, you can offer the customer to receive an email when the product is back in stock. That way, you do not lose the customer, even if the size or color they want is sold out right now.
Tip: When the customer can see the full range, your selection seems wider, and it increases the chance that the customer comes back when the product is in stock again.
Frequently asked questions
Should I show all out-of-stock variants on all products?
Not necessarily. It makes the most sense for fashion products with clear size categories (S, M, L), or when a collection typically sells out in certain sizes first. With very large ranges, or on products where variants are often discontinued permanently, it can cause confusion.
Can the customer add an out-of-stock variant to the cart?
No. When the disabled attribute is set on the option, it cannot be selected. If you build custom JavaScript, you must make sure yourself that out-of-stock variants are blocked, so an "Add to Cart" click does not go through.
Where do I find the current variant loop in my theme?
Search for getInStockVariants or getStockVariants in your theme folder (typically in product.html). That is where you make the change. Remember to save a copy of the file first.
Does it affect Google Shopping or other feeds?
No. Showing out-of-stock variants only changes the product page itself in your store. Product feeds are handled separately and are based on the actual stock quantity per variant.
What happens to the statistics when I show out-of-stock variants?
The conversion rate may rise slightly because more customers sign up for back-in-stock notifications, but you also risk customers leaving because their preferred size is sold out. Consider running a split test before you roll out the change across the whole store.
How do I quickly see whether a variant is in stock in the admin?
Open the product in the admin and look under "Variants". Each variant has its own stock quantity, and you can filter the product overview by stock status.
Can I show the total number of out-of-stock variants?
Yes. Count the rows where cnt is 0 in the loop. You can use it for a message such as "3 of 6 sizes are sold out".
What is the difference between getInStockVariants and getStockVariants?
getInStockVariants() always returns only the variants that have stock. getStockVariants() can give you either in-stock only (with true as the first parameter) or all variants (with false). Use the latter when you want to show out-of-stock options.
Should I delete old out-of-stock variants completely?
If a variant is not coming back, it is cleaner to delete it or hide it completely from the product. Use the display of out-of-stock variants for short-term sellouts and seasons, not for variants that have been permanently discontinued.
Need help? Contact us at support@shoporama.dk.
Related articles
Product profiles and product variants: attributes, sizes, and colors
A guide to product profiles and product variants in Shoporama. Learn how profiles, attributes, values, and variants fit together, and how to set...
Stock synchronization for product variants
How stock synchronization works for products with variants in Shoporama, using CSV import, the REST API, or shared stock across stores.
Back-in-stock emails: Notify customers when products are restocked
Learn how to set up back-in-stock email notifications, so your customers find out when sold-out products are available again in your Shoporama store.
Set products offline automatically when they are out of stock
How to control whether out-of-stock products are shown or hidden automatically in your Shoporama store.
Smarty template variables in Shoporama themes
Overview of the global and page-specific Smarty variables available in Shoporama themes, such as the cart, customer, campaigns, products, and...
Related features
Stock management
Stock entries, warehouse locations, reorder lists, inventory value, and automatic notifications. Avoid overselling with Shoporama's stock management.
Product profiles and variants: set up your product types
Create product profiles, attributes, and variants in Shoporama with their own price and stock, and see what to do when a product has both colors...