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

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

  1. The mobile app is a game changer. I can play anywhere without any lag or crashing. Highly recommend downloading bcgameapp for a better experience.

  2. The app version is a game changer. I can play anywhere and the connection is always stable. Love 881betloginapp.

  3. I’ve been trying a few different sites lately and this one really stands out. The interface is smooth and the payouts are fair. Definitely giving kcwin33 a go for my nightly sessions.

  4. Top notch experience so far. The graphics are crisp and the winning streaks are real. I’ll be spending a lot more time here for sure. vnlf168

  5. Customer support is top notch. They answered all my questions within minutes. Very reliable service. inyy5678

  6. I felt lucky the moment I joined. The odds are great and the community is very welcoming. Definitely my new favorite spot pkluckybet7

  7. I finally found a platform that actually works smooth. The registration process was a breeze and I was playing in minutes. Check out 5jililoginregister for a great experience!

  8. Finally found a site that doesn’t crash during peak hours. The bonuses are actually fair and easy to claim at xin883.

  9. Really impressed with the customer support and the variety of games available. Everything feels very secure and professional. Give x666lcd a go if you want a quality gaming spot.

  10. Finally found a site that doesn’t lag during peak hours. The customer support is also very responsive and helpful. Great experience with brbetamo so far.

  11. Had a bit of a struggle finding a stable platform but panalokalogin works perfectly on my mobile. Great experience so far with the customer support too.

  12. I feel like my luck has actually improved since I started playing here. The bonuses are generous and the graphics are top notch. It is a total win for me. Visit hoki69slot and see for yourself!

Leave a Reply

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