从Woocommerce类别下拉小部件中禁用某些产品类别 [英] Disable some product categories from Woocommerce category dropdown widget

查看:63
本文介绍了从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.

这篇关于从Woocommerce类别下拉小部件中禁用某些产品类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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