Created
August 27, 2014 05:56
-
-
Save bryceadams/85f75c5eac716412910b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function woo_custom_breadcrumbs_trail_add_product_categories ( $trail ) { | |
if ( ( get_post_type() == 'product' ) && is_singular() ) { | |
global $post; | |
$taxonomy = 'product_cat'; | |
$terms = get_the_terms( $post->ID, $taxonomy ); | |
$links = array(); | |
if ( $terms && ! is_wp_error( $terms ) ) { | |
foreach ( $terms as $c ) { | |
$parents = woo_get_term_parents( $c->term_id, $taxonomy, true, ', ', false, array( $c->term_id ) ); | |
if ( $parents != '' ) { | |
$parents_arr = explode( ', ', $parents ); | |
foreach ( $parents_arr as $p ) { | |
if ( $p != '' ) { $links[] = $p; } | |
} | |
} | |
} | |
// Add the trail back on to the end. | |
$links[] = $trail['trail_end']; | |
// Add the new links, and the original trail's end, back into the trail. | |
array_splice( $trail, 1, count( $trail ) - 1, $links ); | |
} | |
} | |
return $trail; | |
} // End woo_custom_breadcrumbs_trail_add_product_categories() | |
add_filter( 'woo_breadcrumbs_trail', 'woo_custom_breadcrumbs_trail_add_product_categories', 10 ); | |
function woo_get_term_parents( $id, $taxonomy, $link = false, $separator = '/', $nicename = false, $visited = array() ) { | |
$chain = ''; | |
$parent = &get_term( $id, $taxonomy ); | |
if ( is_wp_error( $parent ) ) | |
return $parent; | |
if ( $nicename ) | |
$name = $parent->slug; | |
else | |
$name = $parent->name; | |
if ( $parent->parent && ( $parent->parent != $parent->term_id ) && ! in_array( $parent->parent, $visited ) && ! in_array( $parent->term_id, $visited ) ) { | |
$visited[] = $parent->parent; | |
$visited[] = $parent->term_id; | |
$chain .= woo_get_term_parents( $parent->parent, $taxonomy, $link, $separator, $nicename, $visited ); | |
} | |
if ( $link ) { | |
$chain .= '<a href="' . get_term_link( $parent, $taxonomy ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $parent->name ) ) . '">'.$name.'</a>' . $separator; | |
} else { | |
$chain .= $name.$separator; | |
} | |
return $chain; | |
} // End woo_get_term_parents() |
The error is that the filter doesn't exist: woo_breadcrumbs_trail
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This does not give me a trail of categories in breadcrumbs. What could be possible cause of error?