Tagged: QUANTITY field, Shop Page, woocommerce
-
AuthorPosts
-
September 10, 2018 at 8:50 am #1007809
Hi,
I would like to have a quantity selector field in the Enfold product boxes in the shop overview page.I have allready tried adding the quantity selector via the plugin “Quantity Field on Shop Page for WooCommerce”. This adds a working quantity selector but it puts it in between the Enfold shop button and more info button – maybe with some CSS tweaking this could be the solution… but I couldn’t fix the positioning of the quantity field.
September 11, 2018 at 7:59 am #1008227Hey Yannick77,
Please try to add this code to the child theme functions.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->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( ".type-product" ).on( "click", ".quantity input", function() { return false; }); jQuery( ".type-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.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' );
Another user reported it worked (see https://kriesi.at/support/topic/add-a-quantity-field-to-woocommerce-products/#post-690610 – I already modified the code for you [new class name]).
Best regards,
PeterSeptember 11, 2018 at 6:38 pm #1008491Hi Peter,
thanks it worked, I had to play with CSS too make the positioning of the quantity field look better.September 11, 2018 at 6:46 pm #1008500Hi,
I’m glad you got this resolved. If you need additional help, please let us know here in the forums.
Best regards,
Jordan Shannon -
AuthorPosts
- The topic ‘Adding Quantity field in shop overview page – woocommerce’ is closed to new replies.