Skip to content
Advertisement

Custom plus and minus quantity buttons in Woocommerce 3

I’m building custom WordPress and WooCommerce theme and adding custom plus and minus buttons to Product page quantity field. The buttons do update quantity input’s value and I also receive “Item has been added to your cart” notification (on Product page) when I submit Add to Cart. But the cart page doesn’t show any items, neither says the cart is empty.

I can not work out which WooCommerce JS function I’m suppose to hook into, neither how to hook into it. Could I ask for help please?! Thanks in advance!

My HTML layout:

JavaScript

My custom jQuery function:

JavaScript

Advertisement

Answer

Your First code part is made from a customization of global/quantity-input.php Woocommerce template code…

So for testing, I have changed partially that global/quantity-input.php template code with the following (very near to your code):

JavaScript

Now the necessary CSS and revisited jQuery code functions:

JavaScript

Code goes in function.php file of your active child theme (or active theme). Tested and works.

The quantity buttons “plus” and “minus” work perfectly and are displayed this way:

enter image description here

Products are added to cart with the correct quantity:

enter image description here

if you change the quantity field value with plus and minus buttons, the “Update cart” button is activated when any quantity field change.

enter image description here

When you click on “Update cart”, the quantities as correctly updated.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement