Support » Plugin: Qty Increment Buttons for WooCommerce » Quantity buttons firing twice

  • Resolved TakeoK

    (@takeok)


    I’m using a custom product loop template to allow for choosing variations and adding to cart directly from Shop listing pages. I’m using this to pull in the add to cart form, button, etc.

    do_action( ‘woocommerce_’ . $product->get_type() . ‘_add_to_cart’ )

    The template works fine except when I have the QIB plugin installed the Javascript fires twice. So every time you click the + button the quantity goes up by 2 instead of going up by 1… 3, 5, 7, 9, etc.

    Been working on this for 5 hours now trying to fix it with no luck. This is a development site so I can’t share the URL here (although I could share directly with the author in a private message if that’s possible).

    This happens even with a stock theme and all plugins except Woo and QIB disabled.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author taisho

    (@taisho)

    Hello,

    if the step for the product is not set to 2, this is odd behavior. The events are removed and then reattached to avoid multiple calls. You can try to replace function qib_enqueue_script in QIB .php file with one improvement that will appear in the next version, clear cache and see if this solves the issue, although I wouldn’t count on it too much:

    function qib_enqueue_script() { 
    	
    	wc_enqueue_js( '			
    		
    		// Make the code work after page load.
    		$(document).ready(function(){			
    			QtyChng();		
    		});
    
    		// Make the code work after executing AJAX.
    		$(document).ajaxComplete(function () {
    			QtyChng();
    		});
    
    		function QtyChng() {
    			$(document).off("click", ".qib-button").on( "click", ".qib-button", function() {
    				
    				// Find quantity input field corresponding to increment button clicked.
    				var qty = $( this ).siblings( ".quantity" ).find( ".qty" );
    				// Read value and attributes min, max, step.
    				var val = parseFloat(qty.val());
    				var max = parseFloat(qty.attr( "max" ));
    				var min = parseFloat(qty.attr( "min" ));		
    				var step = parseFloat(qty.attr( "step" ));
    				
    				// Change input field value if result is in min and max range.
    				if ( $( this ).is( ".plus" ) ) {			
    					if ( val === max ) return false;			
    					if ( val + step > max ) {
    					  qty.val( max );
    					} else {
    					  qty.val( val + step );
    					}			
    				} else {			
    					if ( val === min ) return false;			
    					if ( val - step < min ) {
    					  qty.val( min );
    					} else {
    					  qty.val( val - step );
    					}			
    				}
    				
    				$( this ).siblings( ".quantity" ).find( ".qty" ).trigger("change");
    				
    			});
    		}
    		
    	' );
    	
    }

    If it doesn’t, you can contact me and post the link to your website: r dot jedraszyk at gma1l.

    Best regards,

    Ryszard

    • This reply was modified 4 months, 1 week ago by taisho.
    • This reply was modified 4 months, 1 week ago by taisho.
    Plugin Author taisho

    (@taisho)

    I’ve just released the 2.3.1 version, so instead of replacing the code as I suggested in my previous post, you can simply try the new release.

    • This reply was modified 4 months ago by taisho.
    Plugin Author taisho

    (@taisho)

    I’m closing this topic because 2 weeks have passed with no activity. Feel free to reopen it if needed.

    • This reply was modified 3 months, 3 weeks ago by taisho.
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.