简体   繁体   English

扩展woocommerce插件

[英]Extend woocommerce plugin

I have wordpress child theme, and in it I can extend woocommerce by creating folder of following structure:我有 wordpress 子主题,在其中我可以通过创建以下结构的文件夹来扩展 woocommerce:

/wp-content/themes/theme-child/woocommerce/single-product/add-to-cart/*.php

But the problem is that I wan't to extend something located in但问题是我不想扩展位于

/wp-content/plugins/woocommerce-plugin/templates/single-product/add-to-cart/*.php

By first approach I can override woocommerce files, but how do I do it for woocommerce-plugin ?通过第一种方法,我可以覆盖woocommerce文件,但是我如何为woocommerce-plugin做到这woocommerce-plugin

To override woocommerce templates without changing anything in woocommerce plugin folder, you need to copy entire templates folder (located in woocommerce plugin) to your active child theme folder and rename it woocommerce (see here ) .要覆盖 woocommerce 模板而不更改 woocommerce 插件文件夹中的任何内容,您需要将整个templates文件夹(位于 woocommerce 插件中)复制到您的活动子主题文件夹并将其重命名为woocommerce 请参阅此处 Like this the active woocommerce templates are now in your child theme folder and you can customize them…像这样,活动的 woocommerce 模板现在位于您的子主题文件夹中,您可以自定义它们......

You can do it by calling the wc_get_template hook, just tell where the files should be overriden:您可以通过调用wc_get_template钩子来完成,只需告诉应该覆盖文件的位置:

add_filter('wc_get_template', 'plugin_wc_templates', 10, 5);
function plugin_wc_templates ($located, $template_name, $args, $template_path, $default_path) {
    $plugin_path = plugin_dir_path( __FILE__ );
    $newtpl = str_replace('woocommerce/templates', $plugin_path. '/templates', $located);
    if ( file_exists($newtpl) )
        return $newtpl;
    return $located;
}

Remember to print $plugin_path variable to make sure that path is being generating ok.请记住打印$plugin_path变量以确保路径生成正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM