• Hi,

    First of all, thank you so much for creating and maintaining such an awesome plugin. It offers more features than many paid plugins I’ve tried.

    I’m trying to achieve something that I’m not sure is currently supported.

    When I add a Filter Widget for WooCommerce products, it displays all taxonomy terms. However, I was wondering if it’s possible to display only selected terms in the filter.

    For example, I may want to display only specific child terms, even if they belong to different parent categories.

    The issue is that each product belongs to multiple categories, but I only want customers to filter products using a few specific terms, such as Cake, Cupcake, etc., instead of displaying the entire category structure.

    If this is already possible using a custom query or developer hook, I would really appreciate it if you could point me in the right direction.

    Otherwise, please consider this a feature request. I believe it would be a valuable addition to the plugin.

    Best regards,

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Dara

    (@dara4)

    Hi skylinks (@skylinks),

    Thank for the kind words, I really appreciate it.

    Yes, this is possible, but it is not available as a setting directly inside the Filter Widget options. The widget allows this through a custom filter hook.

    For taxonomies, you can modify the get_terms() arguments before the terms are loaded using:

    bpfwe/get_terms_args/{query_id}

    First, you would give your filter a unique Query ID under:
    Your filter widget > Query > Filter Query ID

    For example, set it to:
    cake_filter

    Then you can add a custom function in your child theme functions.php file similar to this:

    add_filter( 'bpfwe/get_terms_args/cake_filter', function( $args, $widget ) {
    
    	// Only show these WooCommerce product categories.
    	// Replace these IDs with your own term IDs.
    	$args['include'] = array(
    		123, // Cake
    		456, // Cupcake
    		789, // Muffin
    	);
    
    	return $args;
    
    }, 10, 2 );

    This will make the filter only display those selected taxonomy terms, even if products belong to any other categories.

    The available arguments are the same as WordPress get_terms(), so you can also use this to exclude terms, change ordering, etc.

    For example, to hide certain categories:

    add_filter( 'bpfwe/get_terms_args/cake_filter', function( $args, $widget ) {
    
    	$args['exclude'] = array(
    		111,
    		222,
    	);
    
    	return $args;
    
    }, 10, 2 );

    This specific hook applies to taxonomy terms only. If you are filtering by custom fields, relational fields, or other data sources, the hook is different because the data is generated differently. You can refer to this documentation on the plugin’s website: https://wpsmartwidgets.com/doc/bpfwe-custom-filters-attributes/.

    Let me know if you need further information with how to apply the other hooks.

    Hope this helps!
    Dara

    Thread Starter skylinks

    (@skylinks)

    Hi Dara,

    Thank you so much for pointing me in the right direction. With your help, I was able to achieve what I wanted.

    However, I have to make some small adjustments. Since I was only including the child terms, I have to use the parent argument because the query was returning an empty array.

    Other than that, I have defined a custom order for my terms.

    add_filter( 'bpfwe/get_terms_args/cm_shop_filter', function( $args ) {

    unset( $args['parent'] );

    $allowed_terms = array(
    45,
    54,
    56,
    48,
    );

    $args['include'] = $allowed_terms;
    $args['orderby'] = 'include';

    return $args;

    }, 10, 2 );

    I’m using radio buttons right now with custom styling, but I have to disable hierarchy as it’ll crash the page, as our query contains a parent argument, I believe.

    So far everything is good. However, I was wondering if there is a way to add an “All Products” filter, which basically acts as a reset filter. It should be active initially. I can build something using JS, but if we can add a feature within the plugin, then it’ll be awesome.

    Lastly, Thanks again for awesome support and maintaining this super cool plugin.

    Best Regards

    • This reply was modified 2 weeks, 1 day ago by skylinks.
    Plugin Support Dara

    (@dara4)

    Hi skylinks (@skylinks),

    For an “All Products” option, the filter has a reset button option, so reusing it and changing its label may be the easiest solution. If you specifically need it as an actual option at the top of the taxonomy list, another approach would be creating an “All Products” term and assigning it to all products, which would allow the existing taxonomy filter logic to handle it without custom code. The only missing part would be having it selected by default, but this could also be handled through the URL scheme using ?results=filter-FILTERID.

    Another solution would be adding a checkbox using an HTML widget, above the filter that would act as a shortcut for the existing reset button. It can start checked by default, uncheck when a real filter is selected, and trigger reset when selected again using a few lines of javascript.

    Let me know if any of those solutions work for you.

    Regards,
    Dara

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.