breadcrumbs with woocommerce

4 Replies ·

  1. I’m not sure if you are still supporting older plugins like Breadcrumb Trail or general questions?
    I have Breadcrumb Trail working on a site and have just added Woocommerce (I see you are on a roll with the members plugin addons, an addon for Woocommerce will be extremely useful)
    The site permalinks are /blog/%postname%/ and the Product permalinks are/store/%product_cat%/
    The ‘Store’ (Shop) page is just a placeholder for archive-product in Woocommerce as I understand it.
    When on the Store page the breadcrumbs show Home-> Store-> Products
    and when on a single product page the breadcrumbs show
    Home-> Store-> Products-> product-category-> single-product

    Could you help with a method to remove ‘Products’ from the list. It points to the ‘Store’ page, as does the ‘Store’link, so is redundant?

  2. Justin Tadlock

    I’ve actually rebuilt my breadcrumbs system to be a drop-in package for any theme/plugin. I just haven’t finished getting the Breadcrumb Trail plugin updated yet to use the new system. It should work correctly with WC.

    The double shop/archive link is due to WooCommerce not correctly handling the CPT archive. It bugs me too.

    Probably the most straightforward way to address this would be to add the following code in your theme’s functions.php file:

    add_filter( 'breadcrumb_trail_items', function( $items ) {
        if ( is_singular( 'product' ) ) {
            unset( $items[2] ); // Removes the third item. Note '0' is the first item.
        return $items;
    } );
  3. markmcl

    That helps and works, thanks.
    crumbs now
    Home-> Store-> product-category-> single-product
    when opening in order.
    Clicking on “product-category” loads taxonomy-product_cat.php to display the items in that category, & the breadcrumbs display:
    Home-> Products-> product-category

  4. Justin Tadlock

    I’m assuming you want “Products” to be “Store” there?

    I’ll have to think that over a bit because that would actually be incorrect behavior. But, I’ll look at it and see what I can come up with.

    The problem here is that WooCommerce goes outside the built-in WordPress post type archive system. Because it’s non-standard, it doesn’t work like it should.

  5. Justin Tadlock

    I think this should work for everything:

    add_filter( 'breadcrumb_trail_items', function( $items ) {
        if ( is_singular( 'product' ) ) {
            unset( $items[2] ); // Removes the "products" item.
            } elseif ( is_post_type_archive( 'product' ) ) {
            unset( $items[1] ); // Removes the "products" item
        return $items;
    } );
    add_filter( 'post_type_archive_title', function( $title, $type = '' ) {
        if ( 'product' === $type && function_exists( 'wc_get_page_id' ) ) {
            $shop = wc_get_page_id( 'shop' );
            if ( $shop ) {
                $title = get_post_field( 'post_title', $shop, 'raw' );
        return $title;
    }, 10, 2 );