WordPress filter hook

woocommerce_add_to_cart_quantity

Defined by WooCommerce and fired by 11 plugins in total, running on 7.8M+ sites between them.

“Filters the change the quantity to add to cart.”

How to use woocommerce_add_to_cart_quantity

It's a filter: your callback receives the value and 1 more argument, and must return the (changed) value. Add this to your theme's functions.php or a small custom plugin:

functions.php
add_filter( 'woocommerce_add_to_cart_quantity', function( $quantity, $product_id ) {
	// Change $quantity here.
	return $quantity;
}, 10, 2 );

Argument names come from ShopLentor's source. Other plugins may pass different values: check the call in the plugin you're targeting below.

11 plugins that fire woocommerce_add_to_cart_quantity

Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.

  1. WooCommerce icon WooCommerce7+ million installs apply_filters( 'woocommerce_add_to_cart_quantity', $quantity, $product_id, $variation_id ) includes/class-wc-cart.php:1219
  2. WooCommerce Stripe Payment Gateway icon WooCommerce Stripe Payment Gateway700,000+ installs apply_filters( 'woocommerce_add_to_cart_quantity', $qty, $product_id ) includes/payment-methods/class-wc-stripe-express-checkout-ajax-handler.php:435
  3. ShopLentor icon ShopLentor80,000+ installs apply_filters( 'woocommerce_add_to_cart_quantity', $quantity, $product_id ) includes/modules/backorder/backorder.php:158
  4. FunnelKit Payment Gateway for Stripe WooCommerce icon FunnelKit Payment Gateway for Stripe WooCommerce20,000+ installs apply_filters( 'woocommerce_add_to_cart_quantity', absint( wc_clean( wp_unslash( $_POST['qty'] ) ) ), $product_id ) includes/traits/wc-smart-button-functions.php:403
  5. MStore API icon MStore API2,000+ installs apply_filters( 'woocommerce_add_to_cart_quantity', $quantity, $product_id ) controllers/flutter-woo.php:566
  6. Mini Cart Drawer for WooCommerce icon Mini Cart Drawer for WooCommerce400+ installs apply_filters( 'woocommerce_add_to_cart_quantity', $qty, $item_id ) minicart_lite/modules/class-mcn-settings.php:203
  7. Checkout Gateway for Paddle icon Checkout Gateway for Paddle80+ installs apply_filters( 'woocommerce_add_to_cart_quantity', $quantity, $product_id ) includes/AddToCartSimulator.php:197
  8. Marketing 360® Payments for WooCommerce icon Marketing 360® Payments for WooCommerce30+ installs apply_filters( 'woocommerce_add_to_cart_quantity', absint($_POST['qty']), $product_id ) includes/payment-methods/class-wc-stripe-payment-request.php:942
  9. Price Matrix for WooCommerce icon Price Matrix for WooCommerce10+ installs apply_filters( 'woocommerce_add_to_cart_quantity', 1, $product_id ) frontend/class-frontend-ajax.php:72
  10. PayRivet Payments with Stripe for WooCommerce icon PayRivet Payments with Stripe for WooCommerceFewer than 10 installs apply_filters( 'woocommerce_add_to_cart_quantity', $qty, $product_id ) includes/payment-methods/class-wc-stripe-express-checkout-ajax-handler.php:444
  11. ShopXpert icon ShopXpertFewer than 10 installs apply_filters( 'woocommerce_add_to_cart_quantity', $quantity, $product_id ) incs/features/backorder/class.backorder.php:173

Need a customisation built on this hook?

Tell us what you want to change and which plugin it's for. We'll write it, test it and send it back as a small plugin.