Advertisement
Guest User

WooCommerce multicategory breadcrumb

a guest
May 22nd, 2015
1,611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. <?php
  2. /**
  3. * Shop breadcrumb
  4. *
  5. * @author WooThemes
  6. * @package WooCommerce/Templates
  7. * @version 2.3.0
  8. * @see woocommerce_breadcrumb()
  9. */
  10.  
  11. if ( ! defined( 'ABSPATH' ) ) {
  12. exit;
  13. }
  14.  
  15. if ( $breadcrumb ) {
  16.  
  17. echo $wrap_before;
  18.  
  19. if ( is_single() && get_post_type() == 'product' ) {
  20.  
  21. echo $prepend;
  22.  
  23. if ( $terms = get_the_terms( $post->ID, 'product_cat' ) ) {
  24.  
  25. $referer = wp_get_referer();
  26. foreach( $terms as $term){
  27. $referer_slug = (strpos($referer, $term->slug));
  28.  
  29. if(!$referer_slug==false){
  30. $category_name = $term->name;
  31. $ancestors = get_ancestors( $term->term_id, 'product_cat' );
  32. $ancestors = array_reverse( $ancestors );
  33.  
  34. foreach ( $ancestors as $ancestor ) {
  35. $ancestor = get_term( $ancestor, 'product_cat' );
  36.  
  37. if ( ! is_wp_error( $ancestor ) && $ancestor )
  38. echo $before . '<a href="' . get_term_link( $ancestor->slug, 'product_cat' ) . '">' . $ancestor->name . '</a>' . $after . $delimiter;
  39. }
  40. echo $before . '<a href="' . get_term_link( $term->slug, 'product_cat' ) . '">' . $category_name . '</a>' . $after . $delimiter;
  41. }
  42. }
  43.  
  44. }
  45.  
  46. echo $before . get_the_title() . $after;
  47.  
  48. } else {
  49.  
  50. foreach ( $breadcrumb as $key => $crumb ) {
  51.  
  52. echo $before;
  53.  
  54. if ( ! empty( $crumb[1] ) && sizeof( $breadcrumb ) !== $key + 1 ) {
  55. echo '<a href="' . esc_url( $crumb[1] ) . '">' . esc_html( $crumb[0] ) . '</a>';
  56. } else {
  57. echo esc_html( $crumb[0] );
  58. }
  59.  
  60. echo $after;
  61.  
  62. if ( sizeof( $breadcrumb ) !== $key + 1 ) {
  63. echo $delimiter;
  64. }
  65.  
  66. }
  67. }
  68.  
  69. echo $wrap_after;
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement