• Resolved vilo1968

    (@vilo1968)


    Hi.

    You would need to put the product quantity in the product category view, something similar to what is shown in the image.

    It’s possible?

    Thank you in advance.

    Capture

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi!

    Thanks for reaching out!

    Adding a quantity selector to more areas of your site is possible, but is generally controlled by your theme, though it can be overwritten with custom code.

    What theme are you you using on your site? I recommend reaching out to the theme developers first to see if they have any built in options for you!

    If they do not have any built in options, the following code snippet can be added to your functions.php file and it should do the trick!

    
    <?php
    /**
     * 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->get_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
    			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' );
    

    I hope that helps!

    Plugin Support abwaita a11n

    (@abwaita)

    Hi @vilo1968,

    We’ve not heard back from you in a while, so I’m marking this thread as resolved. Hopefully, the above info was helpful and you were able to find a solution to your problem!

    If you have further questions, please feel free to open a new topic.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Product quantity in category view’ is closed to new replies.