更新时间:2023-12-06 07:50:15
每当实例化$wc_lg = new WC_List_Grid()
时,它都会触发 wp
挂钩.设置全局WP类对象后,实例$wg_lg
将立即对其进行调用.它会触发woocommerce_before_shop_loop
钩子.每当发生这种情况时,$wg_lg
都会再次对其自身调用一个函数.即gridlist_toggle_button()
.
Whenever $wc_lg = new WC_List_Grid()
is instantiated, its going to trigger wp
hook. Right after global WP class object is set up, the instance $wg_lg
is going to call setup_gridlist()
on itself. Its going to trigger woocommerce_before_shop_loop
hook. And whenever that happens, again $wg_lg
is going to call a function on itself. Namely gridlist_toggle_button()
.
我想更改gridlist_toggle_button函数的内容
I want to change the content of the gridlist_toggle_button function
为什么不只是在插件内部进行更改?喜欢覆盖其中的所有内容.
Why not just to change it inside plugin ? Like override everything whats inside it.
全局$ WC_List_Grid;
global $WC_List_Grid;
您怎么知道$WC_List_Grid
有它的名字?它只是一个类名.可以用$foo
或$bar
之类的任何名称实例化.
How do you know that $WC_List_Grid
has its name? Its just a class name. It can be instantiated under any name like $foo
or $bar
.
我假设您在模板的functions.php文件中进行编码.在functions.php和remove_action()
只能在add_action()
发生后才能工作.
I assume that you are coding in functions.php file of your template. Plugins are being loaded before functions.php and remove_action()
can only work after add_action()
happend.
重要提示:要删除一个钩子,请使用$ function_to_remove和$ priority 添加钩子时,参数必须匹配.两者都适用 过滤器和操作.删除失败不会发出警告.
Important: To remove a hook, the $function_to_remove and $priority arguments must match when the hook was added. This goes for both filters and actions. No warning will be given on removal failure.
http://codex.wordpress.org/Function_Reference/remove_action
因此,这实际上仅应用于删除操作,但是这如何帮助您更改函数内部的内容? :
So this should actually work just for removing the action, but how that helps you to change content inside of the function? :
remove_action(
'woocommerce_before_shop_loop',
array('WC_List_Grid', 'gridlist_toggle_button'),
30
);
请注意,您使用的优先级为100
编辑
我发现do_action('woocommerce_archive_description')
发生在 archive- product.php 和 wc模板中-functions.php 恰好在插件中执行woocommerce_before_shop_loop
挂钩操作之前.尝试使用此:
I found out that do_action('woocommerce_archive_description')
happens in archive-product.php and in wc-template-functions.php right before woocommerce_before_shop_loop
hook actions are being executed in plugin. Try to use this:
function remove_plugin_actions(){
global $WC_List_Grid;
remove_action( 'woocommerce_before_shop_loop', array( $WC_List_Grid, 'gridlist_toggle_button' ), 30);
}
add_action('woocommerce_archive_description','remove_plugin_actions');