admin管理员组文章数量:1278976
Suppose the following categories tree in Woo:
Men (slug men)
-- Shoes (slug shoes / was created first)
Women
-- 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?
Suppose the following categories tree in Woo:
Men (slug men)
-- Shoes (slug shoes / was created first)
Women
-- 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?
Share Improve this question asked Oct 30, 2021 at 2:12 Faye D.Faye D. 1266 bronze badges 1- 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 Commented Nov 1, 2021 at 10:59
1 Answer
Reset to default 0It 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.
本文标签:
版权声明:本文标题:hierarchical - Product subcat with duplicate name of a subcat of another cat gets the category name in the slug 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741242332a2364220.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论