WooCommerce hooks: actions, filters, and checkout hooks explained
Table of Contents
- What are WooCommerce hooks?
- Action hooks vs filter hooks
- Where to put hook code
- How to find the right WooCommerce hook
- Common WooCommerce hooks
- Example: add a description to the shop page
- Example: add a note after the add to cart button
- WooCommerce checkout hooks and CheckoutWC
- Tips for working with hooks safely
- Customize your checkout without code
WooCommerce hooks are points in the WooCommerce code where you can run your own function (an action) or change a value before it’s used (a filter), without editing plugin or theme files. You add a hook callback in a child theme’s functions.php or a code snippets plugin, pick the hook that fires where you want your change, and WooCommerce runs your code there.
What are WooCommerce hooks?
WooCommerce uses the same hook system as WordPress, so everything you know about add_action() and add_filter() applies. Because your code lives outside the plugin, WooCommerce updates don’t overwrite it, and you can move it between themes.
Action hooks vs filter hooks
- Actions let you do something at a point, such as printing a notice under the add to cart button.
- Filters let you change data passing through, such as the text on a button or the price shown.
The basic syntax is:
add_action( 'hook_name', 'your_function_name' );
add_filter( 'hook_name', 'your_function_name' );
Your function holds the code. A filter function receives the value, changes it, and must return it. For the full lists, see WooCommerce’s hook reference.
Where to put hook code
Use a child theme’s functions.php or a snippets plugin such as Code Snippets. A plugin keeps the code when you change themes, lets you switch a snippet off without editing files, and gives each snippet a name. Don’t edit WooCommerce’s template files directly; an update replaces your changes.
How to find the right WooCommerce hook
Open the template file that renders the page and read the do_action() calls. For the shop page, look in woocommerce/templates/archive-product.php. WooCommerce’s hook reference lists each hook with its location, and your theme may add its own.
Common WooCommerce hooks
| Page | Hooks to know |
|---|---|
| Shop and product | woocommerce_before_main_content, woocommerce_archive_description, woocommerce_before_single_product_summary, woocommerce_single_product_summary, woocommerce_after_add_to_cart_form, woocommerce_product_meta_end |
| Cart | woocommerce_before_cart, woocommerce_cart_contents, woocommerce_cart_totals_after_order_total, woocommerce_proceed_to_checkout, woocommerce_after_cart |
| WooCommerce checkout | woocommerce_before_checkout_form, woocommerce_checkout_before_customer_details, woocommerce_review_order_before_payment, woocommerce_review_order_after_submit, woocommerce_after_checkout_form, woocommerce_thankyou |
| My Account | woocommerce_before_account_navigation, woocommerce_account_content, woocommerce_before_my_account, woocommerce_after_my_account |
| Mini cart | woocommerce_before_mini_cart, woocommerce_mini_cart_contents, woocommerce_widget_shopping_cart_buttons |
| Emails | woocommerce_email_header, woocommerce_email_before_order_table, woocommerce_email_order_details, woocommerce_email_footer |
Hook names are lowercase, so copy them exactly.
Example: add a description to the shop page
WooCommerce doesn’t show a description under the shop page heading by default. This action adds one:
add_action( 'woocommerce_archive_description', 'my_shop_description' );
function my_shop_description() {
if ( is_shop() ) {
echo '<p>Welcome to our store! Browse our organic coffee beans and coffee gear.</p>';
}
}
Example: add a note after the add to cart button
A note on shipping or returns near the button answers a common last-minute question:
add_action( 'woocommerce_after_add_to_cart_form', 'my_after_add_to_cart_note' );
function my_after_add_to_cart_note() {
if ( is_product() ) {
echo '<p>Free returns within 30 days.</p>';
}
}
WooCommerce checkout hooks and CheckoutWC
The WooCommerce checkout hooks above fire on WooCommerce’s own checkout template. CheckoutWC replaces that template with its own, some of those hooks don’t fire on a CheckoutWC checkout, and others fire in different places. For CheckoutWC, use its own cfw_ hooks instead. CheckoutWC has several hundred, covering the checkout steps, fields, side cart, order bumps, and the thank you page, all listed in the CheckoutWC hooks reference. The visual hook guide shows where each fires on a real checkout. Hooks only fire on pages CheckoutWC renders.
For example, this adds a notice above the checkout steps:
add_action( 'cfw_checkout_main_container_start', function () {
echo '<div class="woocommerce-info">Orders placed after 2pm ship the next working day.</div>';
}, 15 );
You can add PHP like this under CheckoutWC » Advanced » Scripts, in the PHP Snippets box. You often don’t need code at all: in the Checkout Editor, add a + New HTML block to a slot such as Before Express Checkout. See the Checkout Editor guide.
Tips for working with hooks safely
- Test on a staging site first.
- Prefix function names (
my_, your brand) so they don’t clash with other code. - Use conditional checks such as
is_product()so your output only appears where you want it. - Keep a note of each snippet’s purpose.
- Re-test after WooCommerce or theme updates, because hook locations can change.
Customize your checkout without code
If your goal is a better checkout rather than a coding project, CheckoutWC gives you a visual Checkout Editor for fields, badges, and custom blocks, plus the cfw_ hooks when you need code. Plans start at $249 a year for one site.
The simplicity of Shopify with the power of WooCommerce. Replace your WooCommerce checkout page with CheckoutWC to boost sales and reduce cart abandonment.