Woocommerce: wrapper-start.php & wrapper-end.php should have a filter hook for custom templates

Created on 27 May 2018  路  3Comments  路  Source: woocommerce/woocommerce

Working with my own theme found a problem with WooCommerce product template wrapper start & end,
i found static wrapper tag, this should be filterable by filter hook.

in woocommerce\templates\global\wrapper-start.php file

<div id="primary" class="content-area"><main id="main" class="site-main" role="main">

// should be like this
echo apply_filters('woocommerce_templates_wrapper_start', '<div id="primary" class="content-area"><main id="main" class="site-main" role="main">');

in woocommerce\templates\global\wrapper-end.php file

echo '</main></div>';
// should be like this
echo apply_filters('woocommerce_templates_wrapper_end', '</main></div>');

I hope this will be helpful for custom wrapper setup.

pull

20264

Regards

Most helpful comment

You can use the following code to unhook the wrappers should you not need them.

remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );

Then you can use the actions woocommerce_before_main_content and woocommerce_after_main_content to add any wrappers you want for your theme.

So as you can see these are already filterable in a different way so no need to add another filter inside the templates.

All 3 comments

You can use the following code to unhook the wrappers should you not need them.

remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );

Then you can use the actions woocommerce_before_main_content and woocommerce_after_main_content to add any wrappers you want for your theme.

So as you can see these are already filterable in a different way so no need to add another filter inside the templates.

But, i don't understand.
Why to remove the action, whe i can create the file global/wrapper-start.php and write the code inside.
But for me it doesn't work.

But, i don't understand.
Why to remove the action, whe i can create the file global/wrapper-start.php and write the code inside.
But for me it doesn't work.

Did you add this code to yout funcctions.php file?
add_theme_support('woocommerce');

Also please note that the way you chose is called "woocommerce template override" which has its drawback.
using hooks inside your theme to customize woocommerce theme is recommended way based on this https://docs.woocommerce.com/document/woocommerce-theme-developer-handbook/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aonzzung picture aonzzung  路  3Comments

adriandmitroca picture adriandmitroca  路  3Comments

jameskoster picture jameskoster  路  3Comments

maxrice picture maxrice  路  3Comments

pawelkmpt picture pawelkmpt  路  3Comments