1

In permalinks settings the 'Shop Base with Category' /shop/%product_cat%/ permalink setting puts all the hierarchical categories in the url, for example:

http:// mystore.com/shop/parent-category/child-category/product

I want to remove anything between parent-category and product so my urls look like:

http:// mystore.com/shop/parent-category/product

I am pretty sure that setting up urls like this does not cause problems, because I can manually type the shortened url into an address bar and it goes to the same place as the longer one.

Thanks.

2

It's actually quite simple. Use the woocommerce_product_post_type_link_parent_category_only filter:

add_filter( 'woocommerce_product_post_type_link_parent_category_only', '__return_true' );

Tried and tested working.

PS: The code would go into the theme functions file and __return_true() is a WordPress function.

  • I had been working on custom rewrites. This works perfectly, thanks. – AJD May 24 at 14:53
  • You're welcome. :) – Sally CJ May 24 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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