We covered a lot of WooCommerce Checkout customization in the past – it’s evident that the Checkout is the most important page of any WooCommerce website!
Today we’ll code a nice UX add-on: how do we show product quantity inputs beside each product in the Checkout order table? This is great if people need to adjust their quantities on the checkout before completing their order; also, it’s helpful when you have no Cart page and want to send people straight to Checkout and skip yet another click.
In this post, we’ll see how to add a quantity input beside each product on the Checkout page, and then we’ll code a “listener” to make sure we actually refresh the Checkout and update totals after a quantity change. Enjoy!
PHP Snippet: Display Product Quantity Selectors @ WooCommerce Checkout
Note: you may need to adjust alignment between product name and the new quantity input with custom CSS.
/**
* @snippet Item Quantity Inputs @ WooCommerce Checkout
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WooCommerce 7
* @community https://businessbloomer.com/club/
*/
// ----------------------------
// Add Quantity Input Beside Product Name
add_filter( 'woocommerce_checkout_cart_item_quantity', 'bbloomer_checkout_item_quantity_input', 9999, 3 );
function bbloomer_checkout_item_quantity_input( $product_quantity, $cart_item, $cart_item_key ) {
$product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
$product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
if ( ! $product->is_sold_individually() ) {
$product_quantity = woocommerce_quantity_input( array(
'input_name' => 'shipping_method_qty_' . $product_id,
'input_value' => $cart_item['quantity'],
'max_value' => $product->get_max_purchase_quantity(),
'min_value' => '0',
), $product, false );
$product_quantity .= '<input type="hidden" name="product_key_' . $product_id . '" value="' . $cart_item_key . '">';
}
return $product_quantity;
}
// ----------------------------
// Detect Quantity Change and Recalculate Totals
add_action( 'woocommerce_checkout_update_order_review', 'bbloomer_update_item_quantity_checkout' );
function bbloomer_update_item_quantity_checkout( $post_data ) {
parse_str( $post_data, $post_data_array );
$updated_qty = false;
foreach ( $post_data_array as $key => $value ) {
if ( substr( $key, 0, 20 ) === 'shipping_method_qty_' ) {
$id = substr( $key, 20 );
WC()->cart->set_quantity( $post_data_array['product_key_' . $id], $post_data_array[$key], false );
$updated_qty = true;
}
}
if ( $updated_qty ) WC()->cart->calculate_totals();
}
Mini-Plugin: Business Bloomer WooCommerce Change Product Quantity On The Checkout Page
You don’t feel confident with coding? You need customers to update their cart on the Checkout Page? You don’t want to purchase yet another bloated, expensive plugin? Great!
Business Bloomer WooCommerce Change Product Quantity On The Checkout Page is a mini WooCommerce plugin, without the usual hassles. One feature. Lifetime license. No annoying subscriptions. 1 plugin file. A few lines of code. No banners. No up-sells. No WP notifications. Use it on as many websites as you like. Lifetime support. 1-page documentation. No settings dashboard.
Quick demo:
As you can see the plugin is pretty straight forward. Install it. See the magic happen. Simple!
Hi Rodolfo, this is wonderful, as usual! Thank you!
Is there a way to refresh the whole page when the quantity changes, rather than just the order table? When I have other payment options enabled (e.g. Klarna), then instalment estimate isn’t updated as it’s not part of the order table. Thinking refreshing the page instead would be a quick solution?
Jamie, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi!
This was a game changer until I discovered, it doesn’t work while logged out.
Do you know what could cause that this quantity changer is not working while i’m logged out from wordpress? When I go incognito, it’s not changing quantity.
And is there a way to show unit price too as well as the subtotal?
Thanks a lot!
Cathy
Hi Cathy! I just retested this on the latest version of WooCommerce and it still works. Unfortunately this looks like custom troubleshooting work and I cannot help here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R
Hello, how do you add only the plus? Because everything overlaps, it’s ugly
Hey Julie! This snippet adds no plus/minus so it must be your theme doing that
Plus minus doesn’t work. Also I want a remove button as well. It’d be great if you fix the code and update it with remove button. Thanks.
Hi Nada, there are no plus/minus here, so maybe they’re from another plugin or code snippet?
Hi! This is the feature i need on my latest project. The snipped seems not working-the quantity is not changing, nor the total. Can you please take a look? I will be very greatful! I am using Divi as theme builder 🙂
Regards, Albena
Hello Albena, thanks so much for your comment! I just retested this on the latest version of WooCommerce + Storefront theme and it still works. Unfortunately this looks like custom troubleshooting work and I cannot help here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R
is it possible to change the quantity field to + – buttons?
Hi Abu, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi thanks for the snippet. Have added this and see the input selector on the checkout but when I increase/decrease it refreshes over ajax but reverts back. Not updating quantity. Tried popping it into troubleshoot mode and disabling all the plugins etc… assuming a conflict but cant seem to identify the issue. No errors in the console either.
Does this still work with the latest version of Woo? Any thoughts on a fix?
Weird. Do you get any JS errors?
It happens when there are multiple different items..
Only last item quantity is changed, rest is not
Must be some theme/plugin conflict, as it works fine on my test website. Can you disable everything but Woo, install the snippet, switch to Storefront theme, and try again?
Is it possible to do something like that to change or assign values for attributes other than price in WooCommerce Checkout?
I’m trying to assign a cart item attribute and update product price on checkout, but haven’t found the way…
Hi Oswaldo, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Nice snippet, but i have some problem, food ordering site, when customer order same product but different addons, only last frome same products on cart work + – , when all products different , works on all. Some idea for fix ? Thanks
https://prnt.sc/QQHyjlQW3qRU
Thanks Bosko. In such case I believe a custom integration needs to be developed in order to make it work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
hello! great snippet, it works for me, but the display of the price in the product line is not enough, as it is displayed without the snippet. It is especially convenient for the client to see the price too when there are several items in the checkout.
Can you tell me what code to add so that the product amount is also displayed?
Hi Volodymyr, price is meant to update when you update the quantity (checkout does refresh). Did you change anything in my snippet?
It works perfectly but it doesn’t show price in line. Only subtotal. Can you edit snippet please?
Not sure I follow. Can you send me a screenshot of the checkout page without and with the snippet active, and show me the inline price?
Hi Rodolfo, thanks for another great snippet!
I think maybe what Thom is referring to in his comment above is that the Subtotal field seems to be populated by the quantity selector and would like the subtotal line for each product to be displayed as well.
Also, is there a way to display the -+ (subtract, add) signs next to the quantity field, I can see them momentarily when I change the quantity but then they vanish, might be easier for customers to see that the quantity field is editable.
Keep up the good work!
OMG I totally did not see the bug until today. Snippet fixed!
Thank you for this code. I saw a bug. The + – (plus and minus) signs next to the quantity field is vanish whenever I change the quantity on checkout.
I can’t replicate this bug. What theme are you on?