Showing all categories as Breadcrumb in the Woocommerce

Hi,

After going through the Forum, we got the code for showing categories as Breadcrumb in the Woocommerce but it is not as expected. We need to show all categories (Parent as well as sub categories ) in the products page. We need minimum 3-4 level of sub categories of the products to be shown. So expecting help in this matter.

Thank you and best regards,
Bibhash karn

Howdy, @bibhashkarn! Thanks for writing in…if you are using Pro, you can access all of the terms belonging to a particular taxonomy by using the All Terms Looper Provider along with the Layout Builder:

A quick way to get this going would be to drag in one of our new Terms Elements:

You can take one of those variations as a jumping off point and go to its Looper Provider and specify Product Categories as the provided taxonomy to pull in your WooCommerce categories.

If you are using X, you will want to look into using something like WordPress’ provided widgets to access certain taxonomies in a sidebar or something. Anything beyond that would likely require some custom development if that doesn’t suit your exact needs.

Hopefully that helps to point you in the right direction…cheers!

Hi Kory,

When I follow the above instructions (Looper provider: All Terms > Product Categories), the Looper Consumer is pulling in Post Categories, instead of WC Product Categories. Am I doing something wrong? Why could it be pulling in the wrong taxonomy?

Thanks

Gunes

Hey Gunes,

In that case, we need to check your setup. Please open a separate thread and give us WP Admin access in a Secure Note.

Please also give us the URLs where we could see the issue.

Thanks.

Hi,

Thank you for your reply.

Actually, We tried to do as per your suggestion but we were unable to do so. Can you guide through so that we can achieve above requirement. We are using PRO theme and the Breadcrumb is set to appear in the Header Builder of PRO theme. Breadcrumb needs to be appear everywhere in the website except Home page of the website.

Our link for the one of the product page is as below where we want to have all categories (Parent as well as Child) to appear in the Breadcrumb.
https://www.hamroshringar.com/product/nivea-milk-lotion-75-ml/

Thank you and best regards,
Bibhash Karn

Hello Bibhash,

I have checked your site and I do not see a breadcrumb on your homepage. The breadcrumb is displaying on other pages too. The categories (parent and sub-categories) on the breadcrumb are not displaying properly though. To add those categories, please check out this old thread to resolve your issue:

Best Regards.

Hello,

Thank you for the response.

True, there is no breadcrumb on home page. We have breadcrumb all over the website except home page.

Thanks a lot for the above link. These links truly helped us to achieve the thing that we are looking for. Thanks once again.

Thank you and best regards.

Hi Bibhash,

We’re glad that you’re able to solve your issue. If you have any other concerns regarding our theme features, feel free to reach us.

Thank you.

Hello,

Thank you for the response. Sure, if any further concern then will let you know.

Thank you and best regards.

Hi Bibhash,

You are most welcome.

Hello, Sorry to bother once again with the same issue.

With the below code:

add_filter('x_breadcrumbs_data', 'post_parent_trail', 9999999, 2);
function post_parent_trail ($crumbs, $args) {
  if ( is_singular('product') ) {
    global $product;
    $category = get_the_terms( $product->ID, 'product_cat' );
    if ( count( $category ) > 0 ) {
      $cat_array             = array();
      $count = 0;
      foreach( $category as $cat ) {
        $cat_array[$count]['label'] = $cat->name;
        $cat_array[$count]['url']   = get_term_link( $cat->term_id );
        $count++;
      }
      array_splice($crumbs, 2, 0, $cat_array);
    }
  }
  if ( is_singular('post') ) {
    $category = get_the_category( get_the_ID() );
    if ( count( $category ) > 0 ) {
      $cat_array = array();
      $cat_array[1]['label'] = $category[0]->name;
      $cat_array[1]['url'] = get_category_link( $category[0]->term_id );
      array_splice($crumbs, 2, 0, $cat_array);
    }
  }
  return $crumbs;  
}

The categories and sub categories are displayed in alphabetical order. But we actually want something like Home > Shop > Category > SubCategory> SubCategory> SubCategory> Product

for example you can see at below link:
https://www.hamroshringar.com/product/ferfree-korean-hyaluronic-acid-serum-20-ml/
https://www.hamroshringar.com/product/olay-regenerist-micro-sculpting-cream-spf-30-50-ml/
https://www.hamroshringar.com/product/nivea-lipcare-strawberry-4-8-g/

So, hoping for the solution in this matter.

Thank you and best regards.

Hello Bibhash Karn,

Did you created the code or has taken it from an older thread? Please be advised that to be able to accomplish what you need, custom coding is needed. We are unable to provide support for customizations under our Support Policy. If you are unfamiliar with code and resolving potential conflicts, you may select our One or Care service for further assistance.

Best Regards.

Hello,

Thank you for the response. The code is taken from older thread as per your colleague suggestions. You can see the response at above discussion.

Sorry but we think this is some thing that has been solved but we are unable to find in the forum. For your reference the code is taken from older thread with below link.

Hoping for the solution.

Thank you and best regards.

Hello Bibhash Karn,

This is our support policy:

Support includes any questions pertaining to features of the themes or plugins to which You hold a valid and unexpired theme or plugin license. Customization requests are not covered. For example, if You have a question about how to use the bar feature in Pro, a member of Our team will be happy to explain how it works. If You want custom code to change a core feature of the bar feature, that would not be covered. For the avoidance of doubt, a customization request is any request that looks to change something in the theme that can not be altered using native options. The manner and scope of support provided is at Our sole discretion.

By the way, please be advised that a product can have several parent and sub-categories. Adding all those parent categories in the breadcrumb may add confusion. The given code works as expected to display the categories in the breadcrumb. You can see it in one of your product page:

The breadcrumb format which is built-in the theme will usually display Home > Shop > Product Name. With the help of the custom code from the older thread, you now have Home > Shop > Category Parent > Child Category > Grand Child > Product Name.

If this is not what you need, please explain further.

Best Regards.

Hello, Thank you for your response. We understand the limitation of support policy and we respect that. Thanks to the team members for their kind support.

Regarding our issue, we accept that the product can have several parent and sub categories. Only few products have several parent categories else they have only one parent category. There can be child and grand child category as you explained.

We are hoping same as you mentioned as Home > Shop > Category Parent > Child Category > Grand Child > Product Name with the above code but the order is not as mentioned. The categories are ordered alphabetically.

In the below link, Care, Cosmetics, Health & Safety and Women are Parent category but the order of Women is at last i.e is just before the product’s name.
https://www.hamroshringar.com/product/olay-regenerist-micro-sculpting-cream-spf-30-50-ml/

In the below link, Health & Safety is parent category and Skin Care is child, Lip Balm & Treatment is grand child but display order of category is as Home > Shop > Category Parent > Grand Child > Child Category > Product Name (In this product we have only one parent category, child category with one grand child category.) Even though of this the category is order alphabetical not in parent-child basis.
https://www.hamroshringar.com/product/nivea-lipcare-strawberry-4-8-g/

So, hoping for the solution.

Thank you and best regards.

Hello @BibhashKarn,

WooCommerce displays the categories in alphabetical order. This order is then the one being picked up by your custom PHP code and returned for your breadcrumb.

Please edit your product and then uncheck “Health & Safety” and “Skin Care”. The remaining category should be “Lip Bam” and then check your breadcrumb again.

Kindly let us know how it goes.

Hello,

Thank you for the response. Default sort order of product category is alphabetical but we want somethin like “Home > Shop > Category Parent > Child Category > Grand Child > Product Name” as you mentioned above.

We have done as per your suggestion but after edit we have “Lip Balm & Treatment” only which is not as per our requirement. We also want “Health & Safety” and “Skin Care” in the breadcrumb sorted in the parent > child wise instead of sorted alphabetically.

So, hoping for the suggestion in this matter.

Thank you and best regards.

Hi @BibhashKarn,

The code you are using, the category for the specific product return in alphabetical order. While you are adding it into another array to display, it arranges in the way you are seeing it currently. The following article may help you with this.

Please remember that this code is a sample code, and it varies from case to case, and we can’t guarantee it works for you.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.