PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]
Botoscope is currently in early access

Support Forum

You need to log-in to create request (topic) to the support

Standalone category as a "fake child"

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

I'm using HUSKY's product category filter as a multi-select on my category pages, configured to show the child categories of the current category. I have one category —"roses" — that is a standalone top-level category (parent = 0) and must keep its standalone URL; I cannot change its parent. On my"flowers" category page, I'd like the"roses" category to also appear as an option inside the category filter, alongside flowers' real children. What's the correct hook or code to add a specific term to the category filter's term list, without changing its parent? My site is multilingual (WPML, 3 languages), so the solution needs to map flowers→roses per language - if there's a solution for that, I will do the rest of the languages, please help me with just the English one,

 

thank you!

Hello,

This is not something HUSKY supports out of the box, but there is a clean solution using the woof_filter_shortcode_args https://products-filter.com/woof_filter_shortcode_args hook, which fires right before HUSKY renders the filter and gives you full access to the assembled term list.

Here is the code snippet for your functions.php (English only, as requested):

add_filter( 'woof_filter_shortcode_args', function( $args ) {

    // Only run on the"flowers" category page
    $flowers_term = get_term_by( 'slug', 'flowers', 'product_cat' );
    if ( ! $flowers_term ) {
        return $args;
    }

    $queried = get_queried_object();
    if ( ! isset( $queried->term_id ) || $queried->term_id !== $flowers_term->term_id ) {
        return $args;
    }

    // Get the"roses" term (top-level, parent stays 0)
    $roses_term = get_term_by( 'slug', 'roses', 'product_cat' );
    if ( ! $roses_term ) {
        return $args;
    }

    // Inject"roses" into the product_cat term list as a fake child
    if ( isset( $args['taxonomies']['product_cat'] ) ) {
        $args['taxonomies']['product_cat'][ $roses_term->term_id ] = array(
            'term_id'  => $roses_term->term_id,
            'slug'     => $roses_term->slug,
            'taxonomy' => 'product_cat',
            'name'     => $roses_term->name,
            'count'    => $roses_term->count,
            'parent'   => 0,
            'childs'   => array(),
        );
    }

    return $args;
} );

A few notes:

  1. The parent value is intentionally left as 0 so the database record is not changed and your roses URL stays intact.
  2. For WPML: on other languages you only need to replace the slug strings 'flowers' and 'roses' with the translated slugs for that language, or use get_term_by('name', ...) with the translated names. You can wrap multiple language branches inside the same filter if you prefer to keep it in one place.
  3. If you have HUSKY's term caching enabled in settings, flush it once after adding this code.