Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

woocommerce_before_add_to_cart_button

Fires inside the add to cart form on single product pages, before the quantity box and button. Good for notes or extra fields.

  • Type Action
  • From WooCommerce
  • Since 1.3.0
  • Fired in templates/single-product/add-to-cart/simple.php

When it fires

WooCommerce fires this action inside the on single product pages, just before the quantity field and the Add to cart button. It's in the add to cart templates for simple, variable, grouped and external products; for simple products the form only appears when the product can be bought and is in stock.

Because it's inside the form, any input you print here is sent along when the customer adds the product to the cart. The global $product holds the current product.

Parameters

None. Your callback takes no arguments.

Example: Show a dispatch note above the button

PHP
add_action( 'woocommerce_before_add_to_cart_button', function () {
	global $product;
	if ( ! $product instanceof WC_Product || ! $product->is_in_stock() ) {
		return;
	}
	printf(
		'<p class="dispatch-note">%s</p>',
		esc_html__( 'Order before 14:00 for same-day dispatch.', 'my-snippets' )
	);
} );

Good to know

  • Block themes: the Add to Cart + Options block fires this hook too, but for simple products it runs after woocommerce_before_add_to_cart_quantity rather than before it.
  • Extra fields you add here need more code to be saved with the cart item, usually on the woocommerce_add_cart_item_data filter.
  • Product pages are often cached, so don't print anything personal to the visitor.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.