WP SITES

3086 Coded Tutorials & 290 Plugins

Only Show Top Level Parent Categories in WooCommerce Product Categories Widget

This code removes any sub or child categories from the WooCommerce Product categories widget.

You can add the code to the end of your child themes functions file or custom code snippets plugin.

add_filter( 'woocommerce_product_categories_widget_args', 'show_only_parent_product_categories' );
function show_only_parent_product_categories( $args ) {
    $args['parent'] = 0; // Show only top-level categories
    return $args;
}

Tested and works.

See line 294 in wp-content/plugins/woocommerce/includes/widgets/class-wc-widget-product-categories.php to learn more about this filter and the code you can modify when using it.

Leave a Reply

New Plugins