• Resolved ngrudev

    (@ngrudev)


    Hi, I noticed today that in version 1.3.1 it is not possible to add more than 1 quantity of variable product on shop page. It just reload the page, without adding product, with error message “Please choose product options by visiting …”

    • This topic was modified 2 years, 8 months ago by ngrudev.
    • This topic was modified 2 years, 8 months ago by ngrudev.
    • This topic was modified 2 years, 8 months ago by ngrudev.

    The page I need help with: [log in to see the link]

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

    (@quadlayers)

    hello @ngrudev
    please test this with storefront theme and confirm if the issue persists

    Thread Starter ngrudev

    (@ngrudev)

    I confirm there is the same issue with the Storefront theme.

    I forgot to mention that I use custom code to show quantity box on the shop page.

    /**
     * Add quantity field on the archive page.
     */
    function custom_quantity_field_archive() {
    
    	$product = wc_get_product( get_the_ID() );
    
    	//if ( ! $product->is_sold_individually() && 'variable' != $product->product_type && $product->is_purchasable() ) { //niki. ako ne go iskash za variable products. az go iskam
    	if ( ! $product->is_sold_individually() && $product->is_purchasable() ) {
    		woocommerce_quantity_input( array( 'min_value' => 1, 'max_value' => $product->backorders_allowed() ? '' : $product->get_stock_quantity() ) );
    	}
    
    }
    
    add_action( 'woocommerce_after_shop_loop_item', 'custom_quantity_field_archive', 8, 9 );
    
    function custom_add_to_cart_quantity_handler() {
        if (function_exists('is_woocommerce')) {
    	wc_enqueue_js( '
    	jQuery( "body" ).on( "click", ".quantity input", function() {
    		return false;
    	});
    	jQuery( "body" ).on( "change input", ".quantity .qty", function() {
    		var add_to_cart_button = jQuery( this ).parents( ".product" ).find( ".add_to_cart_button" );
    		// For AJAX add-to-cart actions
    		add_to_cart_button.attr( "data-quantity", jQuery( this ).val() );
    		// For non-AJAX add-to-cart actions
    		add_to_cart_button.attr( "href", "?add-to-cart=" + add_to_cart_button.attr( "data-product_id" ) + "&quantity=" + jQuery( this ).val() );
    	});
    	' );
        }
    }
    add_action( 'init', 'custom_add_to_cart_quantity_handler' );
    Thread Starter ngrudev

    (@ngrudev)

    Issue is resolved. The problem is in my custome code. I should remove or comment the line with code

    //add_to_cart_button.attr( “href”, “?add-to-cart=” + add_to_cart_button.attr( “data-product_id” ) + “&quantity=” + jQuery( this ).val() );

    In my case I use ajax and this piece of code should be removed/commented.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Cant add to cart on Shop page when adding variable product more than 1 quantity’ is closed to new replies.