i want to add button plus and minus for qty related when qty clicks then update subtotal without page load.
i am also using the debut theme and the file name is section folder cart-templated.liquid
<button onclick="this.parentNode.querySelector('input[type=number]').stepDown()" >-</button>
<label for="updates_large_{{ item.key }}" class="cart__qty-label" data-quantity-label-desktop>{{ 'cart.label.quantity' | t }}</label>
<input id="updates_large_{{ item.key }}" class="cart__qty-input" type="number"
name="updates[]" value="{{ item.quantity }}" min="0" pattern="[0-9]*"
data-quantity-input data-quantity-item="{{ forloop.index }}" data-quantity-input-desktop data-role="product-quantity-desktop">
<button onclick="this.parentNode.querySelector('input[type=number]').stepUp()" class="plus">+</button>
2
Answers
thanks, but some changes to your code after work. so please check below code.
go to section folder and file cart-templated.liquid in this file find code below and change
you’ll need to use JavaScript (or jQuery) for the client-side logic and Shopify’s AJAX API to update the cart information on the server side. Below is a step-by-step guide to implement this in your cart-template.liquid file under the sections folder.
Step 1: Modify the HTML for Plus and Minus Buttons
First, ensure your plus and minus buttons are properly set up. Your provided code snippet was cut off; here’s how you might complete it for both buttons:
Step 2: Add JavaScript for Quantity Change Function
Within your cart-template.liquid file or in a separate JavaScript file included in your theme, define the changeQuantity function. This function will handle the quantity change and update the cart without reloading the page. If you’re not already loading jQuery in your theme, you might need to, as Shopify themes often use it.
Step 3: Update the Subtotal in the DOM
After successfully updating the cart, you might want to update the subtotal displayed on the page. You can do this in the .then(cart => {…}) portion of the updateCart function. Assuming you have an element that displays the subtotal, you would update its content with the new subtotal value that you can obtain from the cart object returned by Shopify’s AJAX API.
hope it helps