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:
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.
-
WooCommerce7+ million installs
apply_filters( 'woocommerce_add_to_cart_quantity', $quantity, $product_id, $variation_id )includes/class-wc-cart.php:1219 -
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 -
ShopLentor80,000+ installs
apply_filters( 'woocommerce_add_to_cart_quantity', $quantity, $product_id )includes/modules/backorder/backorder.php:158 -
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 -
MStore API2,000+ installs
apply_filters( 'woocommerce_add_to_cart_quantity', $quantity, $product_id )controllers/flutter-woo.php:566 -
Mini Cart Drawer for WooCommerce400+ installs
apply_filters( 'woocommerce_add_to_cart_quantity', $qty, $item_id )minicart_lite/modules/class-mcn-settings.php:203 -
Checkout Gateway for Paddle80+ installs
apply_filters( 'woocommerce_add_to_cart_quantity', $quantity, $product_id )includes/AddToCartSimulator.php:197 -
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 -
Price Matrix for WooCommerce10+ installs
apply_filters( 'woocommerce_add_to_cart_quantity', 1, $product_id )frontend/class-frontend-ajax.php:72 -
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 -
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.