WooCommerce 'remove_action' 在 'init' 钩子中不起作用 [英] WooCommerce 'remove_action' not working in 'init' hook

查看:24
本文介绍了WooCommerce 'remove_action' 在 'init' 钩子中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试修改 WooCommerce 产品过滤器插件以将过滤器添加为 <div class="row"> 而不是 "col-md-6".

I am trying to modify the WooCommerce product filter plugin to add the filter as a <div class="row"> instead of "col-md-6".

functions.php 中,我删除了与创建 col-md-6 的函数挂钩的操作,编写了创建 rows,并添加了与我的新函数挂钩的操作.请参阅下面的代码.

In functions.php, I have removed the actions which hook into functions that create col-md-6, written new functions that create rows, and added actions that hook into my new functions. See code below.

function filter_styling()
{
    echo '<div class="row">';             
} 

function filter_styling2()
{
    echo '</div><div class="row">';            
}

function product_category_filter_changes()
{
    remove_action('woocommerce_before_main_content','oxy_before_breadcrumbs', 19);
    remove_action('woocommerce_before_main_content', 'oxy_after_breadcrumbs', 20);
    add_action('woocommerce_before_main_content', 'filter_styling', 19);  
    add_action('woocommerce_before_main_content', 'filter_styling2', 20);
}
add_action('init','product_category_filter_changes',10);

添加操作正在注册,但不是删除操作.有什么想法吗?

The add actions are registering, but not the remove actions. Any ideas?

谢谢!丹

推荐答案

删除操作只能在已添加操作的情况下进行.因此,'init' 钩子可能为时过早.

Removing an action can only be done when an action has already been added. Because of this, the 'init' hook is likely too early.

我推荐使用 'template_redirect' 动作钩子,它会在插件加载后运行:

I recommend using the 'template_redirect' action hook, which will run after the plugins are loaded:

function product_category_filter_changes()
{
    remove_action('woocommerce_before_main_content','oxy_before_breadcrumbs', 19);
    remove_action('woocommerce_before_main_content', 'oxy_after_breadcrumbs', 20);
    add_action('woocommerce_before_main_content', 'filter_styling', 19);  
    add_action('woocommerce_before_main_content', 'filter_styling2', 20);
}
add_action('template_redirect','product_category_filter_changes');

这篇关于WooCommerce 'remove_action' 在 'init' 钩子中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆