前言这一点,我很清楚SO有多个问题可以解决这个问题。然而,经过他们中的许多人并尝试他们的解决方案后,我仍然没有成功地删除该操作。我尝试的一些SO问题是:
need help removing action from plugin file
remove_action() not working in WordPress plugin
How to remove a WordPress action which uses the current object - $this?
我正致力于在Wordpress中创建一个子主题,该主题利用第三方插件为WooCommerce添加软件许可功能。在尝试自定义此插件时,我正在考虑删除插件添加的操作,并将其替换为修改后的版本。
我要删除的add_action调用是:
add_action( 'woocommerce_order_item_meta_end', array($this->functions, 'woocommerce_order_item_meta_end'), 99, 3 );
此add_action在类WOO_SL_front
中调用,该类定义$this->functions = new WOO_SL_functions();
在我尝试删除此操作时,我使用了以下功能:
//Remove WOO_SL email and order action...
//Add customized version of email and order action
function swsint_remove_actions(){
global $wp_filter, $WOO_SL_functions;
remove_action( 'woocommerce_order_item_meta_end', array($WOO_SL_functions, 'woocommerce_order_item_meta_end'), 99);
error_log(print_R($wp_filter, true));
}
add_action('init', 'swsint_remove_actions');
add_action('woocommerce_order_item_meta_end', 'swsint_woocommerce_order_item_meta_end', 98, 3);
通过此尝试,我无法删除该操作。该功能仍然执行。如您所见,我将已注册的Wordpress操作列表打印到error_log。通过这个,我知道在我尝试删除它之前添加了操作,我相信我已经确认我在remove_action函数中列出了正确的类。相关的输出在这里:
[woocommerce_order_item_meta_end] => Array
(
[99] => Array
(
[000000005807010900000000491e34d0woocommerce_order_item_meta_end] => Array
(
[function] => Array
(
[0] => WOO_SL_functions Object
(
[query_vars] => Array
(
[software_license] => view-license
)
)
[1] => woocommerce_order_item_meta_end
)
[accepted_args] => 3
)
)
[98] => Array
(
[swsint_woocommerce_order_item_meta_end] => Array
(
[function] => swsint_woocommerce_order_item_meta_end
[accepted_args] => 3
)
)
)
从这个输出中,我不确定要对000000005807010900000000491e34d0woocommerce_order_item_meta_end
做什么。它清楚地显示函数所来自的类是WOO_SL_functions
,函数名是woocommerce_order_item_meta_end
。但是,我已经尝试了所有可以考虑调用remove_action函数的变体:
remove_action( 'woocommerce_order_item_meta_end', array($WOO_SL_functions, 'woocommerce_order_item_meta_end'), 99);
remove_action( 'woocommerce_order_item_meta_end', array('WOO_SL_functions', 'woocommerce_order_item_meta_end'), 99);
remove_action( 'woocommerce_order_item_meta_end', array($WOO_SL_front->functions, 'woocommerce_order_item_meta_end'), 99);
remove_action( 'woocommerce_order_item_meta_end', array('WOO_SL_front->functions', 'woocommerce_order_item_meta_end'), 99);
remove_action( 'woocommerce_order_item_meta_end', array('WOO_SL_functions::woocommerce_order_item_meta_end'), 99);
非常感谢任何人都能提供的任何见解!