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

15 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

  10. Nohow… Hmm. Bit basic, yeah? But it does the job. Loads quick enough and there’s a decent selection of games. If you’re not after anything fancy, it’s alright. Take a peek: nohow

  11. Tried my luck on cwibak. Actually quite enjoyed it. User-friendly site, good range of games, and the bonuses are alright. Might stick around for a bit. Give it a burl: cwibak

  12. Hey, I stumbled upon dwindling.net and it looks kinda interesting. Needs a bit more going on, y’know? But the basic idea is solid. Hoping to see some big improvements soon! Check it out: dwindling

  13. Trying out Sprunki Phase 10000 right now. That beat drop in the middle is fire! Love how the characters react to the rhythm. Definitely my new favorite phase.

  14. As someone who’s played many Sprunki mods, Sprunki Phase 10000 finally nails the difficulty curve. The new mechanics add strategic depth without being overwhelming. GG to the devs!

  15. Just started playing Sprunki Phase 10000 and I’m already noticing some cool mechanics. Anyone else having trouble with the timing windows? Still, the core gameplay vibes are solid.

Leave a Reply

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