WordPress filter hook

woocommerce_add_to_cart_qty_html

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

“Filters the quantity HTML for the add to cart message.”

How to use woocommerce_add_to_cart_qty_html

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

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

9 plugins that fire woocommerce_add_to_cart_qty_html

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_qty_html', ( 1 !== $qty ? wc_stock_amount( $qty ) . ' × ' : '' ), $product_id ) includes/wc-cart-functions.php:106
  2. TI WooCommerce Wishlist icon TI WooCommerce Wishlist100,000+ installs apply_filters( 'woocommerce_add_to_cart_qty_html', ( 1.0 !== (float) $data['quantity'] ? esc_html( wc_format_localized_decimal( $data['quantity'] ) ) . ' × ' : '' ), $data['product']->get_id() ) public/wishlist/ajax.class.php:444
  3. WPC Product Quantity for WooCommerce icon WPC Product Quantity for WooCommerce2,000+ installs apply_filters( 'woocommerce_add_to_cart_qty_html', ( $qty > 1 ? (float) $qty . ' × ' : '' ), $product_id ) wpc-product-quantity.php:890
  4. FooSales icon FooSales700+ installs apply_filters( 'woocommerce_add_to_cart_qty_html', ( $default_woocommerce_quantity && $qty > 1 ? absint( $qty ) . ' × ' : ( ! $default_woocommerce_quantity ? abs( $qty ) . ' ' . $foosales_product_cart_quantity_unit . ' ' : '' ) ), $product_id ) admin/class-foosales-admin.php:3420
  5. Free Product Sample for WooCommerce icon Free Product Sample for WooCommerce200+ installs apply_filters( 'woocommerce_add_to_cart_qty_html', ( $qty > 1 ? absint( $qty ) . ' × ' : '' ), $product_id ) public/class-woo-free-product-sample-public.php:572
  6. Free Product Samples for WooCommerce icon Free Product Samples for WooCommerce70+ installs apply_filters( 'woocommerce_add_to_cart_qty_html', ( $qty > 1 ? absint( $qty ) . ' × ' : '' ), $product_id ) public/class-free-product-sample-for-woocommer-public.php:2435
  7. ShopExtra icon ShopExtra10+ installs apply_filters( 'woocommerce_add_to_cart_qty_html', ( $qty > 1 ? absint( $qty ) . ' × ' : '' ), $product_id ) includes/classes/Translations.php:329
  8. Increase average cart value with Cross-Sell icon Increase average cart value with Cross-Sell10+ installs apply_filters( 'woocommerce_add_to_cart_qty_html', $cross_sell_item['qty'] . ' × ', $cross_sell_product_id ) src/Plugin/Plugin.php:1157
  9. Samply icon SamplyFewer than 10 installs apply_filters( 'woocommerce_add_to_cart_qty_html', ($qty > 1 ? absint($qty) . ' × ' : ''), $product_id ) includes/Frontend/SamplyWooCommerce.php:617

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.