Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.