Make Quantity field read-only on product and cart pages - Craft theme

Solved

Make Quantity field read-only on product and cart pages - Craft theme

dhowarth
Tourist
7 2 0

My store only sells one of a kind unique products and need to make the quantity field read-only on the product and cart pages.   it should always be set to 1 when the customer puts the item in their cart and they shouldn't be able to change it.   Am using the Craft theme and there doesn't appear to be a setting which controls this.   Any help is much appreciated.  Thanks.

Accepted Solution (1)
dhowarth
Tourist
7 2 0

This is an accepted solution.

thanks that worked.   also had to make the same changes in the main-cart-items.liquid.

View solution in original post

Replies 10 (10)

Sweet_Savior_3
Shopify Partner
1372 104 145

Hello @dhowarth 

 

Welcome to Shopify Community.

 

Please share your store URL.

 

Thanks

Don't forget to like and accept the solution to help others store owners.
Looking for an expert or Have any queries ? Send query to the Inbox
Coffee Tip ? Pay to shopify.dev.34@gmail.com
From Less To Further !!!
dhowarth
Tourist
7 2 0
Sweet_Savior_3
Shopify Partner
1372 104 145

Your storefront is password protected.

 

Never mind if you can find the quantity input in the code, then please find it and add 'readonly' to the <input> tags.

Don't forget to like and accept the solution to help others store owners.
Looking for an expert or Have any queries ? Send query to the Inbox
Coffee Tip ? Pay to shopify.dev.34@gmail.com
From Less To Further !!!
dhowarth
Tourist
7 2 0

I've tried doing that in the main-product.liquid file and it doesn't appear to work.   See the line I added below in read.  Is this not correct?

 

<input
class="quantity__input"
type="number"
name="quantity"
id="Quantity-{{ section.id }}"
data-cart-quantity="{{ cart_qty }}"
data-min="{{ product.selected_or_first_available_variant.quantity_rule.min }}"
min="{{ product.selected_or_first_available_variant.quantity_rule.min }}"
{% if product.selected_or_first_available_variant.quantity_rule.max != null %}
data-max="{{ product.selected_or_first_available_variant.quantity_rule.max }}"
max="{{ product.selected_or_first_available_variant.quantity_rule.max }}"
{% endif %}
step="{{ product.selected_or_first_available_variant.quantity_rule.increment }}"
value="{{ product.selected_or_first_available_variant.quantity_rule.min }}"
form="{{ product_form_id }}"
readonly

Sweet_Savior_3
Shopify Partner
1372 104 145

Yes thats correct, 

 

if it is not working then the code needs to be checked and changed. 

 

If possible, you can provide the collaborator access for the code editor so I will check and fix the code.

Don't forget to like and accept the solution to help others store owners.
Looking for an expert or Have any queries ? Send query to the Inbox
Coffee Tip ? Pay to shopify.dev.34@gmail.com
From Less To Further !!!
dhowarth
Tourist
7 2 0

Correction... the readonly works as I'm no longer able to edit the quantity field directly.   But I'm still able to change the quantity value with the - or + buttons.   How do i prevent that?

Sweet_Savior_3
Shopify Partner
1372 104 145

In that case just hide the +/- buttons using display:none CSS or comment the +/- buttons html from the code using liquid comments

{% comment %}{% endcomment %}

Don't forget to like and accept the solution to help others store owners.
Looking for an expert or Have any queries ? Send query to the Inbox
Coffee Tip ? Pay to shopify.dev.34@gmail.com
From Less To Further !!!
dhowarth
Tourist
7 2 0

This is an accepted solution.

thanks that worked.   also had to make the same changes in the main-cart-items.liquid.

Sweet_Savior_3
Shopify Partner
1372 104 145

Yes, 

 

Don't forget to like and accept the solution.

Don't forget to like and accept the solution to help others store owners.
Looking for an expert or Have any queries ? Send query to the Inbox
Coffee Tip ? Pay to shopify.dev.34@gmail.com
From Less To Further !!!

webwondersco
Shopify Partner
1200 171 174

@dhowarth Could you please share your store URL with front password?

Web Wonders | Shopify Partner | Connect here!
- Question answered? Mark as Accepted Solution, reply helpful? Click Like
- Hire me, if you want to design, re-design, develop a store, or make changes to the pre-built store.
- a small Coffee Tip would be greatly appreciated. :)..! Instagram