Ask Your Question
4

How can I conceal categories that are not chosen in woocommerce?

asked 2023-05-16 22:40:43 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-05-16 22:45:02 +0000

pufferfish gravatar image

One way to hide categories that are not chosen in WooCommerce is to use a custom code in the functions.php file of your theme. You can use the following code snippet:

add_filter( 'woocommerce_product_categories_widget_args', 'hide_empty_categories' );
function hide_empty_categories( $args ) {
    $args['hide_empty'] = 1;
    return $args;
}

This code will hide all empty categories in the product categories widget. If you want to hide specific categories that are not chosen, you can modify the code to exclude those categories by using their category IDs. For example:

add_filter( 'woocommerce_product_categories_widget_args', 'hide_specific_categories' );
function hide_specific_categories( $args ) {
    $exclude = array( 5, 10, 15 ); // IDs of categories to be excluded
    $args['exclude'] = $exclude;
    return $args;
}

This code will exclude categories with the IDs 5, 10, and 15 from the product categories widget. You can modify the list of IDs to include the categories you want to exclude.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-16 22:40:43 +0000

Seen: 7 times

Last updated: May 16 '23