Suppose the following categories tree in Woo:

Men (slug men)
-- Shoes (slug shoes / was created first)
-- Shoes (slug shoes-women / was created second)

Why is this happening? Both subcats belong to different categories. Why is the category slug appended to the name of the second duplicate subcat?

And anyway, for whatever reason Autommatic decided to program it that way, I need to change it, as the nature of the e-shop I'm building is full of such duplicate subcat names, as it will sell clothing, and there will be the same subcat and even subsubcat names for many categories (Men, Women, Kids, etc)...

Any insight on this?

  • 1
    (Congrats on asking a WooCommerce question that's actually about core WP function, BTW - almost nobody manages that. Unless it turns out it is Woo that's breaking this!)
    – Rup
    Nov 1, 2021 at 10:59

1 Answer 1


It took me two days to figure this out in the proper way, so I'll add it here for anyone else that may need it in the future.

add_filter('wp_unique_term_slug', 'prevent_cat_suffix', 10, 3);
function prevent_cat_suffix($slug, $term, $original_slug)
    if ($term->post_type == 'product' && $term->parent !== 0) {
        return $original_slug;

    return $slug;

As you can see in the code, I've narrowed it down to products only, but you can make it suitable for any other post type also by removing the $term->post_type == 'product' && in the code above.

  • I'm not sure that's the proper way to fix that - you're just undoing what wp_unique_term_slug() has done. Here's the code that's supposed to allow duplicate slugs across taxonomies - I'd work out why that isn't working here.
    – Rup
    Nov 1, 2021 at 10:58
  • Yeah, the part you highlighted is supposed to allow the term to be "duplicate" as long as it belongs to another parent. But in practice it's not. Unfortunately, I don't have the luxury of time, nor is it my job actually to investigate why it's not working (maybe a bug? although it looks fine). That's why I resourced in "undoing", as you said, what it's supposed to do. And TBH, the way I see it, I didn't undo it; in fact I made sure it does what it was originally supposed to do; that is to allow duplicate subcats to exist as long as they are children of different cats.
    – Faye D.
    Nov 2, 2021 at 23:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.