Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将来自其他插件的过滤器应用于woocommerce?_Php_Wordpress_Woocommerce - Fatal编程技术网

Php 如何将来自其他插件的过滤器应用于woocommerce?

Php 如何将来自其他插件的过滤器应用于woocommerce?,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我一直试图从我自己的自定义插件中为WooCommerce应用一个过滤器,但无论我做什么,过滤器都不会启动 网上常见的解决方案不起作用。我试过: 我还尝试将过滤器附加到各种操作点(init、加载插件)和各种优先级(10、20999) 为了测试,我创建了一个简单的单页插件。当过滤器触发时,它应该写入错误日志。该文件位于/wp content/plugins/pluginest.php中 <?php /* * Plugin Name: Plugin TEST * Descript

我一直试图从我自己的自定义插件中为WooCommerce应用一个过滤器,但无论我做什么,过滤器都不会启动

网上常见的解决方案不起作用。我试过:

我还尝试将过滤器附加到各种操作点(init、加载插件)和各种优先级(10、20999)

为了测试,我创建了一个简单的单页插件。当过滤器触发时,它应该写入错误日志。该文件位于/wp content/plugins/pluginest.php中

<?php
/*
 * Plugin Name: Plugin TEST
 * Description: A simple plugin to test
 * Version: 1.0
**/

function my_test_get_template( $template, $template_name, $args ) {    

    error_log('working ...... FILTER ....  ');

    return $template;
}


error_log('working ... ');

add_filter( 'woocommerce_locate_template', 'my_test_get_template', 20, 3);  


我不明白为什么代码不起作用。我知道WooCommerce是活跃的,我编写的其他代码(扩展了WC_EMAIL类)也可以使用。我可以过滤“woocommerce\u email\u类”,没有任何问题,这也很有效。但是模板路径不会触发。有什么明显的错误吗?

所以我没有让过滤器工作,但我找到了解决办法。我没有对路径应用过滤器,而是在email类中添加了一个模板库,用于检查主题中是否有文件,如果没有,则使用插件文件。这允许通过主题覆盖插件模板

在自定义WooCommerce电子邮件的构造调用中,我添加了:

$this->template_base  = $this->get_template_path();
它调用此函数:

public function get_template_path() {

// are we looking for html or plain?
$template = ($this->get_option( 'email_type' ) == 'html') ? $this->template_html : $this->template_plain;

// path to theme woocommerce file overrides 
$theme_path = get_stylesheet_directory() . '/woocommerce/'; 

//plugin path 
$plugin_path = plugin_dir_path( dirname( __FILE__ ) )  . 'templates/';

// if we have a theme file let's use it, otherwise revert to plugin file
$path = (file_exists($theme_path . $template) ) ? $theme_path : $plugin_path;

return $path;       
}


这现在起作用了。这是特定于电子邮件模板路径,但这就是我所需要的

所以我没有让过滤器工作,但我找到了一个解决办法。我没有对路径应用过滤器,而是在email类中添加了一个模板库,用于检查主题中是否有文件,如果没有,则使用插件文件。这允许通过主题覆盖插件模板

在自定义WooCommerce电子邮件的构造调用中,我添加了:

$this->template_base  = $this->get_template_path();
它调用此函数:

public function get_template_path() {

// are we looking for html or plain?
$template = ($this->get_option( 'email_type' ) == 'html') ? $this->template_html : $this->template_plain;

// path to theme woocommerce file overrides 
$theme_path = get_stylesheet_directory() . '/woocommerce/'; 

//plugin path 
$plugin_path = plugin_dir_path( dirname( __FILE__ ) )  . 'templates/';

// if we have a theme file let's use it, otherwise revert to plugin file
$path = (file_exists($theme_path . $template) ) ? $theme_path : $plugin_path;

return $path;       
}

这现在起作用了。这是特定于电子邮件模板路径,但这就是我所需要的