Hi, I am using the below code snippet for adding category breadcrumbs as found on this forum and it is working well, apart from it seems to pull through the top category alphabetically rather than the primary category. Is there a way to set the primary category as the one that pulls through?
For example breadcrumbs would be HOME > SHOP > PRIMARY CATEGORY > PRODUCT
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();
$cat_array[1]['label'] = $category[0]->name;
$cat_array[1]['url'] = get_term_link( $category[0]->term_id );
array_splice($crumbs, 2, 0, $cat_array);
}
}
return $crumbs;
}