我正在尝试修改 WooCommerce 产品过滤器插件以将过滤器添加为 <div class="row">
而不是 "col-md-6"
.
在 functions.php 中,我删除了 Hook 到创建 col-md-6
的函数的操作。 , 编写了创建 row
的新函数s,并添加了与我的新功能 Hook 的操作。请参阅下面的代码。
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);
添加操作正在注册,但不是删除操作。有什么想法吗?
谢谢! 丹
最佳答案
删除 Action 只能在已经添加 Action 时进行。因此,'init'
Hook 可能为时过早。
我建议使用 'template_redirect'
操作 Hook ,它将在插件加载后运行:
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');
关于php - WooCommerce 'remove_action' 在 'init' Hook 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32122643/