我正在尝试修改WooCommerce产品过滤器插件,以将过滤器添加为<div class="row">
而不是"col-md-6"
。
在 functions.php 中,我删除了挂钩到创建col-md-6
的函数的动作,编写了创建row
的新函数,并添加了挂钩的动作我的新功能。请参阅下面的代码。
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);
添加操作正在注册,但不包括删除操作。有什么想法吗?
谢谢! 丹
答案 0 :(得分:10)
只有在添加了操作后才能删除操作。因此,'init'
挂钩可能为时过早。
我建议使用'template_redirect'
动作挂钩,它将在加载插件后运行:
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');