小编Dav*_*ave的帖子

woocommerce_locate_template 从插件而不是主题过滤

我发现这篇关于使用插件而不是主题来覆盖 Woocommerce 模板的文章: https://www.skyverge.com/blog/override-woocommerce-template-file-within-a-plugin/

它似乎几乎可以工作,但它不适用于 woocommerce/templates 目录根目录中的任何模板(例如 single-product.php 或 content-single-product.php)。

为了说明这一点,我有这个过滤器:

add_filter('woocommerce_locate_template', array($this, 'woocommerce_locate_template'), 10, 3);
Run Code Online (Sandbox Code Playgroud)

调用这个函数:

public function woocommerce_locate_template($template, $template_name, $template_path) { 
global $woocommerce; 
al_log('Looking for ' . $template . ', ' . $template_name . ', ' . $template_path); 
$_template = $template; 
if (! $template_path) $template_path = $woocommerce->template_url; 
$plugin_path = $this->my_plugin_path() .'/woocommerce/'; 
//look within passed path within the theme. This is the priority 
$template = locate_template( 
array( 
$template_path . $template_name, 
$template_name, 
) 
); 
//modification: get the template from this …
Run Code Online (Sandbox Code Playgroud)

php wordpress plugins woocommerce

5
推荐指数
0
解决办法
1412
查看次数

标签 统计

php ×1

plugins ×1

woocommerce ×1

wordpress ×1