Search code examples
wordpresswoocommercebreadcrumbs

Set breadcrumb path for woocommerce product, with multiple category


I have a product in multiple categories. The latest woocommerce shows the shortest way as breadcrumb on the product page, but that doesnt make sense for me. I would like to use the primary category of the product as breadrumb trail.

I know that yoast has a function to do that, but it would be better to do it with some custom functions.php code.


Solution

  • Ok, this will work as a solution, so here it is:

    As i found out, woocommerce doesnt show the shortest way as breadcrumb. It shows the newest category which the product is in. As newest I mean that the product category that was created latest.

    So I created a "new primary category", assigned the products to that with importing, and deleted the "original primary category". Then I renamed the "new primary category" to "original primary category".

    Now the newest path is displaying as breadcurmb on product page.

    Before tweaking with category names, make sure you have a backup in case. And you have to refresh your menu links too, because in some case it will point to the deleted category.