Woocommerce - Override the default templates location under the theme directory

As per official woocommerce documentation (here), the proper and safe way to override default woocomerce templates via t

As per official woocommerce documentation (here), the proper and safe way to override default woocomerce templates via theme is to create a sub-folder under the theme directory with the 'default' name /woocommerce and copy the targeted templates into it and make some changes ..

Example: to override the archive-product.php template, copy:

wp-content/plugins/woocommerce/templates/archive-product.php 

to

wp-content/themes/<your-theme>/woocommerce/archive-product.php

So is there any possible way to override the default woocommerce templates folder : /woocommerce under the theme directory and move it to an other folder let say /<your-theme>/plugins/woocommerce ?

in fact, many plugins out there (woocommerce, bbpress among others) suggest creating sub-folder under the theme directory with the name of the plugin (/woocommerce, /bbpress) to hold the overridden templates and in order to bring some organization to my theme folder it does make sens to me to create sub-folder /plugins under my theme directory where i can hold my own templates so archive-product.php would be located under

/<my-theme>/plugins/woocommerce/archive-product.php

and not

/<my-theme>/woocommerce/archive-product.php

as expected.

i looked at those core functions: wc_get_template_part, wc_get_template, wc_get_template_html and wc_locate_template under /includes/wc-core-functions.php but i can't figure out how to override the default location (applying filters ..)

i appreciate your kind help.

As per official woocommerce documentation (here), the proper and safe way to override default woocomerce templates via theme is to create a sub-folder under the theme directory with the 'default' name /woocommerce and copy the targeted templates into it and make some changes ..

Example: to override the archive-product.php template, copy:

wp-content/plugins/woocommerce/templates/archive-product.php 

to

wp-content/themes/<your-theme>/woocommerce/archive-product.php

So is there any possible way to override the default woocommerce templates folder : /woocommerce under the theme directory and move it to an other folder let say /<your-theme>/plugins/woocommerce ?

in fact, many plugins out there (woocommerce, bbpress among others) suggest creating sub-folder under the theme directory with the name of the plugin (/woocommerce, /bbpress) to hold the overridden templates and in order to bring some organization to my theme folder it does make sens to me to create sub-folder /plugins under my theme directory where i can hold my own templates so archive-product.php would be located under

/<my-theme>/plugins/woocommerce/archive-product.php

and not

/<my-theme>/woocommerce/archive-product.php

as expected.

i looked at those core functions: wc_get_template_part, wc_get_template, wc_get_template_html and wc_locate_template under /includes/wc-core-functions.php but i can't figure out how to override the default location (applying filters ..)

i appreciate your kind help.

Share Improve this question edited May 23, 2019 at 8:52 asked May 22, 2019 at 23:35 user34803user34803
Add a comment  | 

1 Answer 1

Reset to default 2

I believe you can use the woocommerce_template_path hook/filter:

// $path defaults to 'woocommerce/' (in your theme folder)
add_filter( 'woocommerce_template_path', function( $path ){
    $my_path = get_stylesheet_directory() . '/plugins/woocommerce/';
    return file_exists( $my_path ) ? 'plugins/woocommerce/' : $path;
} );

It should work whether you're overriding only specific files or all — i.e. you copy all files and folders from wp-content/plugins/woocommerce/templates to your theme.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745470740a4629120.html

相关推荐

  • Woocommerce - Override the default templates location under the theme directory

    As per official woocommerce documentation (here), the proper and safe way to override default woocomerce templates via t

    1小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信