Only want quantity selector to show for products that have more than one product available for Dawn

I’ve seen a few posts about how to do this, but the source file locations don’t exist in Dawn’s code (or at least I can’t find them in any of the code files I’ve checked), only in the older versions.
I only want my quantity selector to show for products that have more than a quantity of one available. Additionally, I want for the “+” button in the quantity selector to be limited to the maximum amount of that particular product that I have available and for it to automatically adjust as people make purchases.

Ex. I have an inventory of 100 for a product, I don’t want for people to be able to click the “+” button on the quantity selector for 101+ products as an error shows (that to a customer that can’t see my inventory levels, looks weird). Instead, I would like for it to say “Quantity Limit Reached”.

Ex2. I have an inventory of 100 for a product and someone purchases 50 of that product. I don’t want for people to be able to still click the “+” button on the quantity selector to the initial 100 of that product I had available, I would want it to limit at 50, or whatever the remaining amount I have left in my inventory is.

@JW94

You need to hire a developer for your requirements as it will take time to setup this.

If you are interested please DM me or mail at shopify.dev.34@gmail.com.

Regards

Twinkle

For Dawn the simplest approach to hiding the qty input for products where all it’s variant have a single inventory qty stocked is to make an alternate template with the quantity block disabled.

To apply an alternative template to a lot of products use either spreadsheets or admin or app workflows.

Spreadsheets - export/import Product CSV, or Inventory CSV to quickly sort and filter in spreadsheets that quantity threshold.

Admin try admin product qty sort, or filter by a collection setup with a condition of 1 qty, or use a search query to find all products of a quantity. For the admin methods then use the product bulk editor to apply alternate templates. There are also apps and services to automate swapping templates with triggers like inventory.

Hire help if you are not experienced with javascript to customize the Dawn itself for multiple variant options with differing inventory amounts as it’s an advanced customization to even interpret vintage tutorials for Dawns javascript design which also uses html/js components.

With multiple variant options per product it requires modifying the onVariantChange javascript to handle variant option selection updating the qty input. Or adding a hard refresh to the page when an new option is selected.

An issue is the section render api isn’t used in dawn like it should be so even if you use something like product.selected_varaint as the crux of logic it’s moot in javascript html replacement.

For stores whose products have 1 variant only , with only either the default variant or a custom single one, they can try the following untested changes that works on page load but not variant option. Note: It is recommended this be an alternate template for single variant products due to lack of javascript integration.

Always backup themes and files before making changes to code

Find the quantity selector code in your Dawn theme in main-product.liquid

Add one of the following logic for a CSS class to the CSS attribute on the container of the quantity elements

{% if product.has_only_default_variant and product.first.variant.inventory_quantity == 1 %}hidden{%- endif -%}
{% if product.variants.size == 1 and product.selected_or_first_available_variant.inventory_quantity == 1 %}hidden{%- endif -%}

Reference: https://github.com/Shopify/dawn/blob/main/sections/main-product.liquid#L134


Becomes:


To add a maximum input validation

Reference: https://github.com/Shopify/dawn/blob/main/sections/main-product.liquid#L144


Becomes:

```markup

UX notes:

Even if the Quantity input is hidden customers will still see an inventory message by clicking the add to cart multiple times for an item with 1 inventory in stock.

For limited inventory amounts with maximums consider either dedicated buttons per-amount or a selection dropdown so it's apparent to users what the upper bound is so they do not have to fumble through +/- buttons to find out. Or a "max" button to autofill qty inputs with the maximum allowed.