Beans icon indicating copy to clipboard operation
Beans copied to clipboard

beans_breadcrumb() should check for false return from get_post_type_archive_link()

Open iCaspar opened this issue 7 years ago • 3 comments

@see https://community.getbeans.io/discussion/wrong-woocommerce-breadcrumbs/ for initial report.

WooCommerce Products have no archive link. So we end up with an entry in $breadcrumbs like

[0] => 'Products'

where [0] should be a url.

Presumably this would be the case for any CPT object for which has_archive is not set or false. Checking for it is easy enough, but what to do in these events?

We probably ought to implement a check for WooCommerce, since this will be a common case. Beyond that some things that come to mind:

  1. We could attempt to find taxonomies/terms belonging to the CPT.
  2. We could insert a placeholder key and then output the PostType label without linking.
  3. We could just bail out of that iteration and leave that bit of the breadcrumb out, since it's essentially inaccessible for a visitor anyway.

iCaspar avatar Apr 05 '18 19:04 iCaspar

Hi there, I found a solution for this case Add code to function.php (child theme)

add_action( 'after_setup_theme', 'woocommerce_support' ); function woocommerce_support() { add_theme_support( 'woocommerce' ); add_theme_support( 'wc-product-gallery-zoom' ); add_theme_support( 'wc-product-gallery-lightbox' ); add_theme_support( 'wc-product-gallery-slider' ); }

Woo will add their breadcrumb by default on all shop pages.

To remove theme breadcrumbs on shop pages(avoid duplicate), just add

add_action ('wp' , 'woo_dup_disable_breadcrumb'); function woo_dup_disable_breadcrumb() { if ( is_woocommerce() ) { // Remove the breadcrumb. add_filter( 'beans_pre_load_fragment_breadcrumb', '__return_true' ); } }

It works, however, if you disable the woocommerce plugin, you need to remove the code above in function.php file. I'm looking for the function that working if woo is disabled but no luck. Tried this solution https://docs.woocommerce.com/document/query-whether-woocommerce-is-activated/ but theme breadcrumb still appear with Woocommerce breadcrumb on shop pages.

tonamphong avatar Apr 17 '18 19:04 tonamphong

@iCaspar Where do we stand on this issue?

hellofromtonya avatar Jun 21 '18 01:06 hellofromtonya

I'm thinking we can roll this issue into the Beans WooCommerce plugin, i.e. yet to be developed. Let's target for that plugin.

hellofromtonya avatar Jun 21 '18 01:06 hellofromtonya