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.
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
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.