Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #690610

    I wanted to add a quantity field to woocommerce archive pages and used this snippet from

     * 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() ) {
    		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', 0, 9 );
     * Add requires JavaScript.
    function custom_add_to_cart_quantity_handler() {
    	wc_enqueue_js( '
    		jQuery( ".post-type-archive-product" ).on( "click", ".quantity input", function() {
    			return false;
    		jQuery( ".post-type-archive-product" ).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 "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' );

    It was working before but after the latest updates from WordPress and Enfold it add’s only one article to the shopping cart instead of for example 3 if I select 3.
    Or sometimes when you select more then one item in related articles it will go to the product page instead of adding the article to the shopping cart when you hit ‘add to shoppingcart’
    I have no idear where it’s going wrong, could you take a look?
    The url is: (product page), shopping page:



    Try changing this:

    add_action( 'woocommerce_after_shop_loop_item', 'custom_quantity_field_archive', 0, 9 );


    add_action( 'woocommerce_after_shop_loop_item', 'custom_quantity_field_archive', 0, 999 );

    So the buttons sit outside the a tag because when you try to interact with them it gets you to the product single view.

    Best regards,


    Thanks Josue, that helped. But the real problem was that the class name in
    jQuery( ".post-type-archive-product" ).on( "click", ".quantity input", function() {
    did not exist anymore.
    When I changed post-type-archive-product to type-product, which does exist, it was working.

    Cheers, Ariane


    hello to all, I want to make the total visible according to the quantities directly on the product page, before clicking the button add to the cart, how can i do it?



    Hi vartgraphic,

    Here is a solution for you

    Show Product Price times Selected Quantity on WooCommerce Product Page

    If you need further assistance please let us know.
    Best regards,

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.