Howdy, I found this wonderful snippet in a previous post, and it almost works perfectly.
// Categories and Subcategories in breadcrumb
// =============================================================================
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();
$count = 0;
foreach( $category as $cat ) {
$cat_array[$count]['label'] = $cat->name;
$cat_array[$count]['url'] = get_term_link( $cat->term_id );
$count++;
}
$cat_array = array_reverse($cat_array);
array_splice($crumbs, 2, 0, $cat_array);
}
}
return $crumbs;
}
// =============================================================================
But for some reason it swaps the location of the category with subcategory.
Any ideas on how to fix?
Example URL: https://usatcorp.com/shop/airlink-shark-fin-mag-mount-adapter-6001112/
Thank you,
Jesse @ USAT