WooCommerce + Breadcrumb NavXT
Quick snippet
Published
I've been working with WooCommerce, a free WordPress plugin to add e-commerce support to a website. I was working on including breadcrumbs to help make the navigation of the store more intuitive. I wanted to include the base path of the store (i.e.: Products) in the breadcrumb path, and I found that the Breadcrumb NavXT plugin treated me with much more respect than WooCommerce's built-in breadcrumb feature.
However, on a single product page, the default breadcrumb path didn't include the WooCommerce Product Category taxonomy path, so instead of seeing something like
Products > Parts > Brakes > Pads > Brake Pad
I saw
Products > Brake Pad
The trouble with categories (in blog software at least) is that a post can be in one or more categories, but the user still expects to be able to see a detailed breadcrumb path telling him how he got to whatever page he's viewing. I came up with a quick fix using Breadcrumb NavXT to look for the first available WooCommerce Product Category and build a breadcrumb path based on that.
function product_cat_breadcrumbs($post, $return = false) {
$taxonomy_name = 'product_cat';
$terms = get_the_terms($post->ID, $taxonomy_name);
$term_count = 0;
foreach ($terms as $term) {
$term_count++;
global $bcn_admin;
if ($bcn_admin !== null) {
// Load options
$bcn_admin->breadcrumb_trail->opt = wp_parse_args(get_option('bcn_options'), $bcn_admin->breadcrumb_trail->opt);
$bcn_admin->breadcrumb_trail->term_parents($term->term_id, $taxonomy_name);
return $bcn_admin->breadcrumb_trail->display($return);
}
break;
}
// If we didn't find any terms, fallback to default behaviour.
if ($term_count == 0)
return bcn_display($return);
} 





I was curious about Chrome, but Michelle hates having to adjust to new stuff on our laptop (she doesn't even like me letting iTunes update to the newest version!). I use Firefox, based only on the nebulous (word of the day) notion that it downloads less stuff to my hard drive and generally leaves my PC less cluttered than IE would.
I can honestly say I've never heard of Unbuntu Linux before...