This article was last manually reviewed for data accuracy on 12 November 2025.
WooCommerce relies on a massive network of Action and Filter hooks to build its pages. Every element—from the breadcrumbs to the related products—is attached to a specific hook location.
By leveraging this system, you can customize a WooCommerce store completely. This article will show you the safe, correct, and update-proof method for precisely removing or overriding these built-in functions using WordPress’s native hook management tools. Doing this improperly (such as by editing core plugin files or using incorrect priorities) can break your site during updates.
For a deep dive into WooCommerce Hooks refer to: WooCommerce Hooks and Filters: Complete Guide with Examples
What You’ll Learn:
- How to find the exact hook name, function name, and crucial priority parameter.
- The correct PHP implementation of remove_action() and remove_filter().
- Troubleshooting the #1 reason removals fail: load order.
- Advanced techniques for handling class-based hooks.
WooCommerce Hook Removal Best Practices & Essential Tools Checklist
Rule #1: Never Edit Core WooCommerce Plugin Files
This is the foundational principle of WordPress development. WooCommerce is constantly updated. If you modify any file inside the /wp-content/plugins/woocommerce/ directory, the next time the plugin updates, all your changes will be overwritten, potentially leading to catastrophic site failure.
In short, all customization must be added externally.
Where to Add Custom Hook Removal Code (Child Theme vs. Plugin)
Your custom hook removals must reside in a file that is update-proof:
- Child Theme’s functions.php file – This is the most common place for theme-specific customizations.
- A custom site-specific plugin – This is ideal because it separates your functionality from your theme, making your customizations portable if you ever switch themes.
- Specialized Plugin – You can also use a tool like the Code Snippets plugin to manage these easily without creating a physical plugin file.
Essential Tools for Finding WooCommerce Hook, Function, and Priority
To remove a hook, you need three pieces of information: the hook name, the function name, and the priority.
Read our comprehensive article on How How to find WooCommerce Hooks & Filters for a complete and clear understanding.
Finding the Right Target: WooCommerce Hook Name, Function, and Priority
Step 1: Visually Identify the Element (Using a Hook Plugin)
Use a visual hook plugin to identify the hook name (e.g., woocommerce_single_product_summary). If you can’t use a visual tool, your only option is to search the core WooCommerce code.
Step 2: How to Search the WooCommerce Codebase Manually
The fastest way to find the specifics is to search the WooCommerce plugin folder for the add_action or add_filter call associated with your hook name.
Example: To find what builds the summary area of a single product, search the WooCommerce plugin files for: add_action( ‘woocommerce_single_product_summary’.
Step 3: Finding the Exact Function Name and Priority Value
Searching the code will yield results like this, which are often found in files like wp-content/plugins/woocommerce/includes/wc-template-hooks.php:
// Example from WooCommerce code
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );Analysis: If you want to remove the Product Title, you must target the function woocommerce_template_single_title at priority 5.
WooCommerce Hook Removal: The Correct PHP Code Implementation
Understanding remove_action() and remove_filter() Core Syntax
The syntax for removal mirrors the syntax for adding, requiring the hook name, the function name, and the priority:
remove_action( 'hook_name', 'function_to_remove', priority );
remove_filter( 'hook_name', 'function_to_remove', priority );Functionally, remove_action and remove_filter are aliases, but for code clarity, you should use the function that matches the original add_ function (add_action -> remove_action).
Troubleshooting: The #1 Reason remove_action Fails (Load Order)
The single most common reason a hook removal fails is load order. You cannot remove an action before it has been added by WooCommerce. If you place remove_action(…) directly into your functions.php, it often executes too early, and the action list it is targeting is still empty.
The “Proper” Fix: Wrapping Hook Removal in wp_loaded or init
The correct method is to wrap your remove_action calls inside another custom function and hook that function to a later hook, such as init or wp_loaded. This ensures that all of WooCommerce’s core functions have already been loaded and executed before you attempt to remove them.
Code Example: How to Remove the Default WooCommerce Product Title
| Parameter | Value |
|---|---|
| Hook | woocommerce_single_product_summary |
| Function | woocommerce_template_single_title |
| Priority | 5 |
The Wrong Way (Runs Too Early):
// WRONG - This runs too early and fails because the action hasn't been added yet.
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );The Right Way (Runs Later, After WooCommerce Loads):
/**
* Remove the default product title hook.
* Hooking to 'wp_loaded' ensures WooCommerce functions are available.
*/
add_action( 'wp_loaded', 'my_remove_product_title' );
function my_remove_product_title() {
// The three parameters MUST match the original add_action call exactly.
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
}Code Example: How to Remove a Product Tab (Using a Filter Hook)
To remove the default “Reviews” tab, you must modify the array of tabs passed through the filter.
/**
* Removes the default 'Reviews' product tab using a filter hook.
* The priority (98) is set high to ensure the function runs late.
*/
add_filter( 'woocommerce_product_tabs', 'my_remove_reviews_tab', 98 );
function my_remove_reviews_tab( $tabs ) {
// Check if the 'reviews' key exists and remove it from the array.
if ( isset( $tabs['reviews'] ) ) {
unset( $tabs['reviews'] );
}
return $tabs; // MUST return the modified array
}How to “Override” WooCommerce Hooks (Remove, Then Replace Logic)
The true power of WooCommerce customization lies in the ability to override an element: removing the default function and replacing it with your own or simply moving it to a different location.
Example: Moving the Product Price
The price is attached at priority 10. We want to move it after the product excerpt, which is at priority 20.
add_action( 'wp_loaded', 'my_move_product_price' );
function my_move_product_price() {
// 1. Remove the original price function (Hook, Function, Original Priority)
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
// 2. Add the SAME function back with a new, later priority (25)
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 25 );
}Example: Replacing the Product Title with Custom Markup
To replace the title, you first remove the default function and then substitute it with your own custom function at the same priority level.
add_action( 'wp_loaded', 'my_replace_product_title' );
function my_replace_product_title() {
// 1. Remove the original title function (Priority 5)
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
// 2. Add your own custom function at the same priority (5)
add_action( 'woocommerce_single_product_summary', 'my_custom_product_title', 5 );
}
/**
* Custom function to display the product title with custom HTML.
*/
function my_custom_product_title() {
// Using custom class for styling
echo '<h1 class="my-custom-product-title-override">' . get_the_title() . ' <span style="color: red;">(Special Edition)</span></h1>';
}Advanced: Removing a WooCommerce Hook from a Class Method
The most frustrating challenge developers face is removing a hook when the function is a method inside a class, not a standalone function.
The Problem: When a method is added as a hook, the function_to_remove parameter of remove_action must be an array: array( $object_instance, ‘method_name’ ). You need to access the specific instance of that class object.
Example: Removing the Cross-Sells section from the Cart page. The function responsible is cross_sells_display, which is a method within the WC_Cart class. The WC_Cart object instance is globally accessible via WC()->cart.
add_action( 'wp_loaded', 'my_remove_cart_cross_sells' );
function my_remove_cart_cross_sells() {
// Check if WooCommerce object is loaded
if ( ! function_exists( 'WC' ) || ! isset( WC()->cart ) ) {
return;
}
// The function is 'cross_sells_display' inside the 'WC_Cart' object (WC()->cart)
// The original hook call is add_action( 'woocommerce_cart_collaterals', array( WC()->cart, 'cross_sells_display' ), 10 );
remove_action(
'woocommerce_cart_collaterals', // Hook Name
array( WC()->cart, 'cross_sells_display' ), // Array containing the class instance and method name
10 // Priority
);
}Successfully executing this requires deep knowledge of the WooCommerce internal object structure, which proves the code’s authoritative nature.
Hooks vs. Template Overrides: When to Choose Which Customization Method?
Choosing the right customization strategy is key to long-term site health.
Use Hooks When: Adding, Removing, Re-ordering Elements, or Modifying Data
- You want to add or remove a single self-contained element (like the “Sale” badge or product meta data).
- You want to re-order elements that are already attached to the same hook (like moving the price relative to the title).
- You want to modify data (like changing tab titles or product prices).
Use Template Overrides When: Fundamentally Changing HTML/CSS Structure
- You need to fundamentally change the HTML structure or markup of a large section.
- Example: If you want to wrap the product title, price, and rating in a new custom <div> structure for a unique layout, using multiple hook removals and additions becomes unwieldy. In this case, it is safer to copy the relevant template file (e.g., single-product/add-to-cart/simple.php) to your child theme’s structure and modify the HTML directly.
Rule of Thumb: Always attempt to use a hook first. If you find yourself fighting the HTML hierarchy, it is time to override the template file.
Conclusion: Mastering WooCommerce Hook Removal for Robust Customization
Learning the removal and overriding of WooCommerce actions and filters is the one of the most important skills for a developer building on the platform. By following these technical guidelines, you ensure your store is robust, fast, and protected from future plugin updates.
Recap the Key Takeaways:
- Safety First: All customization code belongs in a child theme or custom plugin.
- Find Your Target: You need the exact hook, function, and priority to succeed.
- Use wp_loaded: Always wrap remove_action and remove_filter in a function hooked to init or wp_loaded to guarantee correct execution timing.
- Master Classes: For class-based functions, use the array( $object, ‘method’ ) array syntax for the function parameter.
Frequently Asked Questions (FAQ)
FAQ: CSS vs. Hook Removal for Hiding Elements (Performance Debate)
While technically possible, using CSS (display: none;) is highly discouraged for professional development. The element and all its underlying PHP/SQL code are still loaded and processed by the server and browser. Removing it with a hook (remove_action) prevents the function from ever being called, resulting in cleaner HTML, better performance, and a lower server load.
What is the difference between remove_action and remove_filter?
Functionally, they are aliases. Both functions use the same underlying WordPress API (_remove_all_actions) to detach a function from a list. However, you should use remove_action when removing a function that was originally added with add_action (a function that adds content), and remove_filter for functions added with add_filter (a function that modifies data). This enhances code readability and adherence to convention.
My remove_action is still not working! What else could be wrong?
The problem is almost always the priority parameter. It is the only parameter that does not result in a PHP error if mismatched, leading to silent failure. The original priority must match exactly. If you are absolutely certain of the priority, double-check that you have spelled the function name and hook name correctly, as these are case-sensitive strings.
Did this help? Send a sip
Leave a Reply