If you have structure of categories like this:
- Main Category
- Category 1
- Category 1-1
- Category 2
- Category 2-1
- Category 1
And if you want show in breadcrumbs bar all categories like this:
Home | Main Category | Category 1 | Category 2 | Category 1-1 | Category 2-1 | Product name
So just try find code in /goodstore/template/simple-shortcodes/bereadcrumbs.php lines 81 – 104
//WOOCOMMERCE
if (is_product_category()) {
$terms = get_term_by('slug', get_query_var('term'), 'product_cat');
} else {
$terms = get_the_terms(get_the_ID(), 'product_cat');
if (!empty($terms)) {
$terms = current($terms);
}
}
if (!empty($terms)) {
$parent = get_term_by('id', $terms->term_id, 'product_cat');
// climb up the hierarchy until we reach a term with parent = '0'
$term_parent[] = $parent;
if (isset($parent->parent) && sizeof($parent->parent) > 0) {
while ($parent->parent != '0') {
$parent = get_term_by('id', $parent->parent, 'product_cat');
$term_parent[] = $parent;
}
$term_parent = array_reverse($term_parent);
foreach ((array) $term_parent as $trm) {
echo '<a href="' . get_term_link($trm, 'product_cat') . '">' . ($trm->name ) . '</a>';
}
}
}
and change it to this:
//WOOCOMMERCE
if (is_product_category()) {
$terms = get_term_by('slug', get_query_var('term'), 'product_cat');
} else {
$terms = get_the_terms(get_the_ID(), 'product_cat');
}
$cats_breadcrumbs = array();
$bread_items = array();
foreach ((array) $terms as $key => $term) {
if (!empty($term)) {
$term_parent = array();
$parent = get_term_by('id', $term->term_id, 'product_cat');
// climb up the hierarchy until we reach a term with parent = '0'
$term_parent[] = $parent;
if (isset($parent->parent) && sizeof($parent->parent) > 0) {
while ($parent->parent != '0') {
$parent = get_term_by('id', $parent->parent, 'product_cat');
$term_parent[] = $parent;
}
$term_parent = array_reverse($term_parent);
foreach ((array) $term_parent as $k => $trm) {
if (!isset($cats_breadcrumbs[$key]) || !is_array($cats_breadcrumbs[$key])) {
$cats_breadcrumbs[$key] = array();
}
if(!in_array($trm->slug, $bread_items)){
$term_link = get_term_link( $trm ,'product_cat');
$cats_breadcrumbs[$k][$key] = '<a href="'.$term_link.'">' . ($trm->name ) . '</a>';
$bread_items[] = $trm->slug;
}
}
}
}
}
foreach ($cats_breadcrumbs as $cat) {
echo implode('', $cat);
}
Leave a Reply
You must be logged in to post a comment.