从Woocommerce类别下拉小部件中禁用某些产品类别
问题描述:
我正在寻找一种解决方案,以在商店页面侧边栏中的标准woocommerce类别小部件中隐藏特定类别,我正在使用下拉菜单。
I'm searching for a solution to hide specific categories in the standard woocommerce category widget that is in the sidebar on the shop page, i'm using the dropdown.
我已经搜索过,但似乎可以在任何地方找到它,尝试过重建多个脚本,但似乎无法弄清楚。.
I've searched but can seem to find it anywhere, tried en rebuild multiple scripts but cant seem to figure it out..
在此先感谢
答
您可以尝试使用以下代码,在这些代码中可以禁用一些在下面定义它们的产品类别术语ID:
You can try to use the following code where you will be able to disable some product category terms Ids defining them below in this code:
add_filter('woocommerce_product_categories_widget_dropdown_args', 'widget_product_categories_disable_terms', 10, 1);
add_filter('woocommerce_product_categories_widget_args', 'widget_product_categories_disable_terms', 10, 1);
function widget_product_categories_disable_terms( $args ) {
// Excluding coma separated term IDs from product category
$args['exclude'] = array( 12, 18 );
return $args;
}
代码进入活动子主题(活动主题)的function.php文件。经过测试,可以正常工作。
Code goes in function.php file of your active child theme (active theme). Tested and works.