WooCommerce: Change Product Quantity @ Checkout Page

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!

You can clearly see that there is a new quantity input inside the “Order Review” section of the WooCommerce Checkout page. On change, the Checkout will refresh and update totals.

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        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @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!

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

30 thoughts on “WooCommerce: Change Product Quantity @ Checkout Page

  1. Hi,

    This snippet is working great, but I encountered an issue in one specific case. When there is one item in the cart and the quantity is changed to 0, the cart total set to 0 and the product is removed from the cart. The cart should either redirect to the cart page or show a notice indicating that the cart is empty. Currently, the issue only resolves if the page is refreshed.

    Thank you!

  2. 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?

    1. 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!

  3. 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

    1. 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

  4. Hello, how do you add only the plus? Because everything overlaps, it’s ugly

    1. Hey Julie! This snippet adds no plus/minus so it must be your theme doing that

  5. 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.

    1. Hi Nada, there are no plus/minus here, so maybe they’re from another plugin or code snippet?

  6. 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

    1. 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

  7. is it possible to change the quantity field to + – buttons?

    1. 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!

  8. 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?

    1. Weird. Do you get any JS errors?

      1. It happens when there are multiple different items..
        Only last item quantity is changed, rest is not

        1. 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?

  9. 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…

    1. 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!

  10. 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

    1. 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!

      1. 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?

        1. Hi Volodymyr, price is meant to update when you update the quantity (checkout does refresh). Did you change anything in my snippet?

          1. It works perfectly but it doesn’t show price in line. Only subtotal. Can you edit snippet please?

            1. 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?

              1. 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!

                1. OMG I totally did not see the bug until today. Snippet fixed!

                  1. 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.

                    1. I can’t replicate this bug. What theme are you on?

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *