Resetting woocommerce breadcrumbs (Product Permalinks)

WordPress 6 posts 2 voices

  1. Woocommerce provides additional settings for its plugin in Settings-> Permalinks, in a section similar to the standard wordpress settings entitled ‘Product Permalinks’

    It offers

    Standard 	https://mysite/product/sample-product/
    Shop base 	https://mysite/shop/sample-product/
    Shop base with category 	https://mysite/shop/product-category/sample-product/
    Custom Base

    as choices. I have tried Shop base, but it seems to give inconsistent results as I remember from local install, sometimes showing Shop-> Products->item instead of just Shop-> item, so I left at Standard for the live install. Shop and Products are the same address.

    With this setting you get (navigating through the various pages) Home->Products->Music->Albums until you take the next step to single- product when you revert to Home->Products->Woo Album #2 instead of desired Home->Products->Music->Albums->Woo Album #2

    I presume using the ‘Shop base with category’ option will give the desired results, but if I change to that now, it breaks things giving 404’s.
    Is there a way to do this and repoint the addresses. A plugin I looked at offers a link by link repair, but I thought there might be a simpler way with htaccess file.

    I think that if I left the change until when I tip out all the sample data, any new products added would be fine anyway?

  2. We’re really talking about 2 different things here: 1) WooCommerce permalinks and 2) Breadcrumbs.

    For #1, that’s outside of what I can probably help with. Dealing with permalink issues is something you’ll need to bring directly to the plugin author. My only suggestion is to visit Settings > Permalinks in the admin (only visit; no need to save). What this does is flush your rewrite rules. It could help.

    For #2, we can do breadcrumbs however you want with Breadcrumb Trail. I just need a link to one of your product pages for reference and to know exactly how you want the trail to be set up.

  3. What this does is flush your rewrite rules magic :), you learn more everyday. I suppose, being so simple most people know this.

    we can do breadcrumbs however you want with Breadcrumb Trail great. I had it in my head that permalinks somehow governed the breadcrumbs. (now set to /shop/theme-category/sample-product)

    At the moment, when at the Shop page https://amazingmomentscq.com.au/shop/ the breadcrumbs are Home->Shop->Products; Shop and products are the same address. Home->Shop would be good. I think ‘Products’ is Woo custom post type.

    Further into the shop, at
    https://amazingmomentscq.com.au/shop/theme-category/sample-product/woo-album-1/

    It would be good if the breadcrumbs could be
    Home->Shop->Music->Albums->Woo Album#1
    which is equivalent to
    Home->Shop->theme-category->sub-category->single-product

  4. You should be able to define the taxonomy when you call breadcrumb_trail() like so:

    breadcrumb_trail(
    	array(
    		/* some other arguments here. */
    
    		'post_taxonomy' => array(
    			'product' => 'product_category'
    		)
    	)
    );

    I’m assuming product is the right post type and product_category is the right category name.

    “Shop” or “Products” (not sure which one) shouldn’t be showing. This is unless you have an actual page you’ve created with one of those names, which shouldn’t be needed.

  5. my bad;
    Post Type is: product
    Product categories: product_cat
    Product tags: product_tag

    Shop is a blank page Woocommerce creates on plugin install.
    In their words: “This is the base page of your shop – this is where your product archive will be.”

    The template used to display the page is archive-product.php. The page can be edited like any page, and content added will be will displayed above the content woo adds (categories of products or products or both )

    One of the choices they suggest in Permalinks is https://amazingmomentscq.com.au/product/sample-product/ which is what I have set now. Any other choice brings in the mixup with Shop and or Product. It is fine.

    Breadcrumb Trail is called in functions.php and this is what I have now

    if ( ! function_exists( 'woocommerce_breadcrumb' ) ) {
    
    	function woocommerce_breadcrumb() {
    
    		 if ( function_exists( 'breadcrumb_trail' ) ) breadcrumb_trail(); 
    
    	}
    
    }
    
    add_filter( 'breadcrumb_trail_args', 'amazingstorefront_breadcrumb_trail_args' );
    
    function amazingstorefront_breadcrumb_trail_args( $args ) {
    
        $args['labels']['browse'] = __( '', 'breadcrumb-trail' );//remove label
    
        $args['post_taxonomy']['post'] = 'category';
    
        $args['post_taxonomy']['product'] = 'product_cat';
    
        $args['show_on_front'] = false;
    
        return $args;
    }

    This is working to this step in getting to the single product
    Home->Products->Music->Albums
    both ‘Music’ and ‘Albums’ are categories (product_cat). ‘Albums’ is child category of ‘Music’.
    When you go to
    Home->Products->Music->Albums->Woo Album #1
    (Woo Album #1 is a single product) the Breadcrumbs go to
    Home>Products>Music>Woo Album #1
    leaving out ‘Albums’

    I’ve been reading
    https://github.com/justintadlock/breadcrumb-trail/blob/master/inc/breadcrumbs.php
    and the part

    // If the taxonomy is hierarchical, list its parent terms.
    		
    		// Add the term name to the trail end.

    and hope this means the trail can be set to display
    Home->Products->Music->Albums->Woo Album #1

  6. I think I see the issue and why “Albums” is being left out. It’s because you’ve selected both the “Music” and “Albums” categories. If you simply select “Albums”, it should work correctly.

    The problem is that there’s really no good way for Breadcrumb Trail to know which category is the “priority” (for lack of a better word). So, what it’s going to do is pick the first category with the categories sorted by ID.