Add to Cart Quantity Plus & Minus Buttons

Here’s a quick snippet you can simply copy/paste to show a “+” and a “-” on each side of the quantity number input on the WooCommerce single product page.

This snippet comes with a jQuery script as well, as we need to detect whether the plus or minus are clicked and consequently update the quantity input. jQuery might look difficult to many, but the beauty of this is that you don’t need to have a degree in jQuery – just copy/paste and see the magic happen.

<?php
// 1. Show plus-minus buttons
add_action( 'woocommerce_after_quantity_input_field', 'jwc_display_quantity_plus' );
function jwc_display_quantity_plus() {
    echo '+';
}

add_action( 'woocommerce_before_quantity_input_field', 'jwc_display_quantity_minus' );
function jwc_display_quantity_minus() {
    echo '-';
}

// 2. Trigger update quantity script
add_action( 'wp_footer', 'jwc_add_cart_quantity_plus_minus' );
function jwc_add_cart_quantity_plus_minus() {
    if( ! is_product() && ! is_cart() ) 
        return;

    wc_enqueue_js("
        $( document ).on( 'click', 'button.plus, button.minus', function() {
            varqty = $( 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();
                } elseif ( val > 1 ) {
                    qty.val( val - step ).change();
                }
            }
        });
    ");
}
?>

Comments

9 responses to “Add to Cart Quantity Plus & Minus Buttons”

  1. casinobigbola looks promising. Still checking it out, but the initial vibe is good. Find some fun at casinobigbola.

  2. Alright guys, tried my luck on bbccasino.net. Selection of games is solid, and the mobile experience is smooth. Had a few decent wins, too! Give it a spin if you haven’t already: bbccasino

  3. Yo, been messing around on loto288 and gotta say, it’s pretty fun. Quick registration and a good variety of lotto games. Worth tossing a few bucks in, who knows? Give loto288 a shot: loto288

  4. Just checked out phbet2, and I gotta say, it seems good. Might be my new go-to spot! Check it out here phbet2

  5. Yo, CB33! Just checked it out. Not bad, not bad at all. Solid site. Worth a look. Check it out here cb33

  6. Alright, 16betviplogin… VIP access, huh? Sounds fancy. Logged in no problem, site’s smooth. Giving it a thumbs up! Go give it a shot at 16betviplogin

  7. Jili333login is where it’s at for some of the best Jili games! Easy to log in and loads of fun to be had. You should try it: jili333login

  8. Getting the KK33gamedownload was a breeze. Smooth gameplay and the app is well optimized for my phone. Try the download path here: kk33gamedownload

  9. TT88nohu is pretty decent! The graphics are nice and the gameplay is smooth. Plus, they have a bunch of different game to choose from. Get started here: tt88nohu

Leave a Reply to loto288 Cancel reply

Your email address will not be published. Required fields are marked *