-
AuthorPosts
-
September 7, 2018 at 11:36 am #1007057
Hello fellows,
I already talked with WooCommerce support regarding this issue, so I’ll ask for your help to double-check the following.
I’ll provide you a couple of example, resuming, some products are not showing all the parent categories as they should, but others are.
1st example: https://www.aderal.es/desarrollo/onwa/producto/frigorifico-f143z/
If you check the breadcrumbs you can see “Frigorificos / 2 puertas”. The first is the main cat, the second the child.2nd example: https://www.aderal.es/desarrollo/onwa/producto/campana-extractora-ct60z/
This one is wrong and I don’t really understand how to figured out. It should be “Campanas Extractoras / Extraplanas”. Why? Because if you check the back-end, in the sidebar box (category products) there’s a flag on both cat and sub-cat.I think you can better understand this by looking the back-end.. temporary access in Private Content.
Thanks in advance
DavideSeptember 10, 2018 at 3:10 pm #1007940Hey aderal2016,
This is not a bug – by default the breadcrumb function will “cut” the hierarchy with the first child category. However you can easily overwrite the default breadcrumb function with this code – you can add it to the child theme functions.php:
add_filter('avia_breadcrumbs_trail','avia_custom_woocommerce_breadcrumb', 15, 2 ); function avia_custom_woocommerce_breadcrumb( $trail, $args ) { global $avia_config; if(is_woocommerce()) { $front_id = avia_get_option('frontpage'); $home = isset( $trail[0] ) ? $trail[0] : ''; $last = array_pop($trail); $shop_id = function_exists( 'wc_get_page_id' ) ? wc_get_page_id( 'shop' ) : woocommerce_get_page_id( 'shop' ); $taxonomy = "product_cat"; // on the product page single page modify the breadcrumb to read [home] [if available:parent shop pages] [shop] [if available:parent categories] [category] [title] if(is_product()) { //fetch all product categories and search for the ones with parents. if none are avalaible use the first category found $product_category = $parent_cat = array(); $temp_cats = get_the_terms(get_the_ID(), $taxonomy); if(!empty($temp_cats)) { foreach($temp_cats as $key => $cat) { if($cat->parent != 0 && !in_array($cat->term_taxonomy_id, $parent_cat)) { $product_category[] = $cat; $parent_cat[] = $cat->parent; } } //if no categories with parents use the first one if(empty($product_category)) $product_category[] = reset($temp_cats); } //unset the trail and build our own unset($trail); $trail = ( empty( $home ) ) ? array() : array( 0 => $home ); if(!empty($shop_id) && $shop_id != -1) $trail = array_merge( $trail, avia_breadcrumbs_get_parents( $shop_id ) ); if(!empty($parent_cat)) $trail = array_merge( $trail, avia_breadcrumbs_get_term_parents( $parent_cat[0] , $taxonomy ) ); if(!empty($product_category)) { foreach ($product_category as $key => $data) { $trail[] = '<a href="' . get_term_link( $product_category[$key]->slug, $taxonomy ) . '" title="' . esc_attr( $product_category[$key]->name ) . '">' . $product_category[$key]->name . '</a>'; } } if( ! empty( $last ) ) { $trail['trail_end'] = $last; } } } return $trail; }
Best regards,
PeterSeptember 10, 2018 at 5:31 pm #1007974Hi Peter,
First of all thanks for your support, but something got wrong :(
Please check the website, there’s a “tiny” error :D I tried to delete the code you provided to get back but the error is still there.
Did I do something wrong?:D
Cheers,
DavideSeptember 10, 2018 at 8:03 pm #1008065Hi,
I added the code for you and the error is gone now :)
You can i.e. test it here: https://www.aderal.es/desarrollo/onwa/producto/campana-extractora-ct60z/
Best regards,
PeterSeptember 11, 2018 at 10:57 am #1008313Thank you so much :)
September 11, 2018 at 11:02 am #1008315Hi,
Glad I could help you :)
Best regards,
Peter -
AuthorPosts
- The topic ‘[WOOCOMMERCE] Breadcrumbs not working properly’ is closed to new replies.