WordPress filter hook

woocommerce_stock_amount_cart_item

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

How to use woocommerce_stock_amount_cart_item

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_stock_amount_cart_item', function( $stock_amount, $cart_item_key ) {
	// Change $stock_amount here.
	return $stock_amount;
}, 10, 2 );

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

16 plugins that fire woocommerce_stock_amount_cart_item

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_stock_amount_cart_item', wc_stock_amount( preg_replace( '/[^0-9\.]/', '', $cart_totals[ $cart_item_key ]['qty'] ) ), $cart_item_key ) includes/class-wc-form-handler.php:858
  2. Essential Addons for Elementor icon Essential Addons for Elementor1+ million installs apply_filters( 'woocommerce_stock_amount_cart_item', apply_filters( 'woocommerce_stock_amount', preg_replace( "/[^0-9\.]/", '', filter_var($cart_item_quantity, FILTER_SANITIZE_NUMBER_INT) ) ), $cart_item_key ) includes/Traits/Helper.php:340
  3. Add to Cart Redirect for WooCommerce icon Add to Cart Redirect for WooCommerce6,000+ installs apply_filters( 'woocommerce_stock_amount_cart_item', wc_stock_amount( preg_replace( '/[^0-9\.]/', '', $cart_totals[ $cart_item_key ]['qty'] ) ), $cart_item_key ) public/class-change-quantity-checkout.php:124
  4. CartSuite icon CartSuite5,000+ installs apply_filters( 'woocommerce_stock_amount_cart_item', wc_stock_amount( preg_replace( '/[^0-9\.]/', '', $qty ) ), $cart_item_key ) includes/frontend/frontend.php:290
  5. Booking Activities icon Booking Activities3,000+ installs apply_filters( 'woocommerce_stock_amount_cart_item', $desired_quantity, $cart_item_key ) controller/controller-woocommerce-blocks.php:146
  6. Force Sell for WooCommerce icon Force Sell for WooCommerce600+ installs apply_filters( 'woocommerce_stock_amount_cart_item', 0, $item['key'] ) includes/store-api.php:48
  7. Food Online for WooCommerce icon Food Online for WooCommerce300+ installs apply_filters( 'woocommerce_stock_amount_cart_item', wc_stock_amount(preg_replace('/[^0-9\.]/', '', filter_var($_POST['quantity'], FILTER_SANITIZE_NUMBER_INT))), $cart_item_key ) classes/class-fdoe-ajax.php:31
  8. Androapp icon Androapp300+ installs apply_filters( 'woocommerce_stock_amount_cart_item', apply_filters( 'woocommerce_stock_amount', preg_replace( "/[^0-9\.]/", '', filter_var($data['quantity'], FILTER_SANITIZE_NUMBER_INT)) ), $cart_item_key ) class-pw-wp-woocommerce.php:352
  9. Wholesale Order Table for WooCommerce icon Wholesale Order Table for WooCommerce70+ installs apply_filters( 'woocommerce_stock_amount_cart_item', self::get_request_quantity('quantity', '0'), $cart_item_key ) classes/class-otfw-ajax.php:215
  10. Awesome Checkout Templates icon Awesome Checkout Templates40+ installs apply_filters( 'woocommerce_stock_amount_cart_item', apply_filters( 'woocommerce_stock_amount', preg_replace( "/[^0-9\.]/", '', $quantity ) ), $cart_item_key ) public/front-checkout.php:568
  11. SaleDash icon SaleDash10+ installs apply_filters( 'woocommerce_stock_amount_cart_item', wc_stock_amount( preg_replace( '/[^0-9\.]/', '', $request['quantity'] ) ), $cart_item_key ) includes/api/class-w2w-rest-cart-controller.php:409
  12. Ajax mini cart for Woocommerce icon Ajax mini cart for WoocommerceFewer than 10 installs apply_filters( 'woocommerce_stock_amount_cart_item', apply_filters( 'woocommerce_stock_amount', preg_replace( "/[^0-9\.]/", '', filter_var( sanitize_text_field( $_POST['quantity'] ), FILTER_SANITIZE_NUMBER_INT ) ) ), $cart_item_key ) src/zt-front-end.php:367
  13. Arshida Toolkit for WooCommerce icon Arshida Toolkit for WooCommerceFewer than 10 installs apply_filters( 'woocommerce_stock_amount_cart_item', wc_stock_amount( preg_replace( '/[^0-9\.]/', '', $quantity ) ), $cart_item_key ) src/WC/Main.php:158
  14. OrderFloor icon OrderFloorFewer than 10 installs apply_filters( 'woocommerce_stock_amount_cart_item', wc_stock_amount( $raw ), $cart_key ) src/CartValidator.php:283
  15. ShareDisc icon ShareDiscFewer than 10 installs apply_filters( 'woocommerce_stock_amount_cart_item', wc_stock_amount( preg_replace( "/[^0-9\.]/", '', $cart_totals[ $cart_item_key ]['qty'] ) ), $cart_item_key ) admin/class-sharedisc-admin.php:2199
  16. Single Page Shopping icon Single Page ShoppingFewer than 10 installs apply_filters( 'woocommerce_stock_amount_cart_item', wc_stock_amount( preg_replace( '/[^0-9\.]/', '', $cart_totals[ $cart_item_key ]['qty'] ) ), $cart_item_key ) includes/class-awcs-wc-cart-actions.php:141

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.