add_filter to ‘woocommerce_before_main_content’ [closed]
IT Nursery
June 3, 2022
0
I added a filter in functions.php and change priority very high and low to 1 but every time the parameter is an empty string””;
add_filter( 'woocommerce_before_main_content','wc_start_layout');
function wc_start_layout($content){
$content="";
return $content;
}
What I’m doing wrong?
1 Answer 1
woocommerce_before_main_content is not a filter hook, it’s an action hook, so don’t expect it to return something, because nothing cares about what an action hook callback function returns, whereas for filters hooks, you will always see something waiting for the returned result:
That action hook is used by WooCommerce itself to insert the breadcrumbs for example, here is a place (among others) where WooCommerce exposes this action hook, see this code (templates/archive-product.php:16-24):
Now if you investigate the function woocommerce_breadcrumb(), you will see that it doesn’t modify something it received, in fact, it’s purpose is to output the breadcrumbs.
Moral of the story, an action hook will not allow you to alter a variable, you will need to find a filter hook for that.