- This topic has 5 replies, 3 voices, and was last updated 3 years, 2 months ago by David.
-
AuthorPosts
-
January 27, 2021 at 12:05 pm #1636084Alberto
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.
January 27, 2021 at 5:52 pm #1636287LeoStaffCustomer SupportHi there,
That is handled by the WooCommerce plugin itself so you will need to check with their support team.
It will require modifying their product category add to cart output unfortunately.
January 28, 2021 at 4:22 am #1636749AlbertoWoocommerce support gave me the following code to add to the functions.php file.
I don’t want to edit this file … could it be added in another way, for example using hooks?
Thank you in advance
<?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' );
January 28, 2021 at 5:30 am #1636809DavidStaffCustomer SupportHi there,
that needs to go in a Child Themes functions.php or you can add it using the Code Snippets plugin.
January 28, 2021 at 5:33 am #1636813AlbertoThanks for your answer. Would you tell me how I have to proceed using Code Snippets? Thank you!
January 28, 2021 at 7:03 am #1637100DavidStaffCustomer SupportInstall this plugin:
https://wordpress.org/plugins/code-snippets/
It will add a Snippets menu to your Dashboard, create a New Snippet. Paste in that code, and Save 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.