Cart Quantity + and -

4 replies · opened Dec 31, 2016

TtriplewhatDec 31, 2016

How do I get the buttons to change qty on the cart page and shop quickview page. Is there a plugin I need or something?

SSemicolon WebSTAFFJan 2, 2017

Hello,

This is currently provided only as a Template. However this can be easily made workable by adding the following JS code at the bottom of the Page just after the js/functions.js JS File Linking:


    jQuery(document).ready( function($){

        $(".plus").click(function(){
            var productQuantity = $('.qty').val(),
                intRegex = /^\d+$/;

            if( intRegex.test( productQuantity ) ) {
                var productQuantityPlus = Number(productQuantity) + 1;
                $('.qty').val( productQuantityPlus );
            } else {
                $('.qty').val( 1 );
            }

            return false;
        });

        $(".minus").click(function(){
            var productQuantity = $('.qty').val(),
                intRegex = /^\d+$/;

            if( intRegex.test( productQuantity ) ) {
                if( Number(productQuantity) > 1 ) {
                    var productQuantityMinus = Number(productQuantity) - 1;
                    $('.qty').val( productQuantityMinus );
                }
            } else {
                $('.qty').val( 1 );
            }

            return false;
        });

    });

This will definitely work fine. Hope this Helps!

Let us know if we can help you with anything else or if you find any issues.

TtriplewhatJan 4, 2017

Thank you for the help, although this does work, it changes all the values instead of just the line I'm on. Please help.

SSemicolon WebSTAFFJan 4, 2017

Hello,

Oops! We actually provided you with the above code for the Shop Single page which has a single Quantity Updater. Please use the following code tofix this for the Cart Page:


	jQuery(document).ready( function($){

		$(".plus").click(function(){
			var productQuantity = $(this).parents('.quantity').find('.qty').val(),
				intRegex = /^\d+$/;

			if( intRegex.test( productQuantity ) ) {
				var productQuantityPlus = Number(productQuantity) + 1;
				$(this).parents('.quantity').find('.qty').val( productQuantityPlus );
			} else {
				$(this).parents('.quantity').find('.qty').val( 1 );
			}

			return false;
		});

		$(".minus").click(function(){
			var productQuantity = $(this).parents('.quantity').find('.qty').val(),
				intRegex = /^\d+$/;

			if( intRegex.test( productQuantity ) ) {
				if( Number(productQuantity) > 1 ) {
					var productQuantityMinus = Number(productQuantity) - 1;
					$(this).parents('.quantity').find('.qty').val( productQuantityMinus );
				}
			} else {
				$(this).parents('.quantity').find('.qty').val( 1 );
			}

			return false;
		});

	});

This will definitely work fine. Let us know if we can help you with anything else or if you find any further issues.

TtriplewhatJan 5, 2017

Perfect thank you very much!

Have the same question, or something new?

Sign in to the Canvas dashboard to reply or open your own topic. Canvas owners get direct help from the SemiColonWeb team.

Reply on the dashboard