Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kabbo508/e977a9674d02d71ebff111eecd9a5b0f to your computer and use it in GitHub Desktop.
Save kabbo508/e977a9674d02d71ebff111eecd9a5b0f to your computer and use it in GitHub Desktop.
jQuery code for increment or reduction by “+”, ” -” button click
/*
Jquery for for Quantity Plus-Minus Button
@ code from https://code.mukto.info
*/
add_action( 'wp_footer', 'mukto_add_cart_quantity_plus_minus' );
function mukto_add_cart_quantity_plus_minus() {
wc_enqueue_js( "
$(document).on( 'click', 'button.plus, button.minus', function() {
var qty = $( this ).parent( '.quantity' ).find( '.qty' );
var val = parseFloat(qty.val());
var max = parseFloat(qty.attr( 'max' ));
var min = parseFloat(qty.attr( 'min' ));
var step = parseFloat(qty.attr( 'step' ));
if ( $( this ).is( '.plus' ) ) {
if ( max && ( max <= val ) ) {
qty.val( max ).change();
} else {
qty.val( val + step ).change();
}
} else {
if ( min && ( min >= val ) ) {
qty.val( min ).change();
} else if ( val > 1 ) {
qty.val( val - step ).change();
}
}
});
" );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment