Plus and minus buttons for the WooCommerce cart quantity
The cart page of WooCommerce uses a number input for the quantity. On a phone the spinner arrows are tiny or missing, and many stores want large “−” and “+” buttons instead. A short script adds them, keeps the limits of the input and updates the cart totals by itself.
Problem: Changing the quantity in the cart on a phone is awkward, and after changing it the customer still has to find and press “Update cart”.
Solution: Add the buttons around every .quantity input.qty with jQuery, change the value with the input’s own stepUp()/stepDown() so min, max and step are respected, add them again after WooCommerce replaces the cart HTML (updated_cart_totals), and click “Update cart” after a short pause.
The script
( function ( $ ) {
function addButtons() {
$( '.woocommerce-cart-form .quantity' ).each( function () {
const $box = $( this );
if ( $box.find( '.ha-qty' ).length ) {
return;
}
$box.find( 'input.qty' )
.before( '<button type="button" class="ha-qty ha-qty--minus" aria-label="Decrease">−</button>' )
.after( '<button type="button" class="ha-qty ha-qty--plus" aria-label="Increase">+</button>' );
} );
}
let timer;
$( document.body ).on( 'click', '.ha-qty', function () {
const input = $( this ).siblings( 'input.qty' ).get( 0 );
if ( ! input ) {
return;
}
if ( $( this ).hasClass( 'ha-qty--minus' ) ) {
input.stepDown();
} else {
input.stepUp();
}
$( input ).trigger( 'change' );
clearTimeout( timer );
timer = setTimeout( function () {
$( '[name="update_cart"]' ).prop( 'disabled', false ).trigger( 'click' );
}, 600 );
} );
$( addButtons );
$( document.body ).on( 'updated_cart_totals', addButtons );
}( jQuery ) );
stepUp() and stepDown() stay within the min and max attributes that WooCommerce sets (the stock limit, or 1 for products sold individually), so no parsing and clamping is needed. The pause collects several clicks into one cart update. After the update WooCommerce replaces the cart form with new HTML, which is why the buttons are added again on updated_cart_totals; the click handler is delegated to document.body and keeps working.
The minimum in the cart is 0: setting the quantity to 0 and updating removes the item, as in the standard form.
Enqueue it on the cart page only
add_action( 'wp_enqueue_scripts', function () {
if ( is_cart() ) {
wp_enqueue_script( 'ha-cart-qty', get_theme_file_uri( 'js/cart-qty.js' ), [ 'jquery', 'wc-cart' ], '1.0.0', true );
}
} );
Style
.woocommerce-cart-form .quantity {
display: inline-flex;
align-items: center;
}
.ha-qty {
width: 2.5rem;
height: 2.5rem;
font-size: 1.25rem;
line-height: 1;
}
.woocommerce-cart-form .quantity .qty {
width: 3.5rem;
text-align: center;
}
NOTE: The same buttons on the single product page need no automatic update, only the value change; reuse the click handler without the timer there. Some themes already add their own buttons, so check the markup first, or the customer sees two pairs.
Update (2023): The Cart block, the default in new stores since WooCommerce 8.3, has its own quantity selector with buttons and does not use this form. The script is for the classic [woocommerce_cart] page.