Woocommerce breadcrumb missing store link

I have a WordPress site that uses woocommerce (on the inside page), my URL structure for the store page is as follows:

MySite / store /

breadcrumb on woocommerce pages only shows a home link: You are here: Home

and the URL of my product page:

MySITE / product category / category _name /

show my page on the store page as follows:

You are here: Home 

also shown as below:

 You are here: Home 

I need to do it like:

You are here: Home / shopping / category _name

I checked the permalink options, but that seems OK. I checked the breadcrumb.php template file, it seems that it considers the shop () page to be the main page of my site.

How can I fix this, should I change breadcrumb.php or is there an error in my settings? Thanks in advance.

+6
source share
5 answers

I found out that the pattern code was in the header.php of my judgment topic folder, and the author of this topic did not write code for products or product category pages, so I added

 elseif (is_single() && get_post_type() == 'product'){ $posts_page_id = get_option('page_for_posts'); $posts_page_url = get_permalink($posts_page_id); echo '<li>';$bar = "shopping"; if(get_option_tree('blog_name', '', false)) /*$bar=get_option_tree('blog_name', '', false);*/ echo "<a href=".home_url()."/shopping/>$bar</a></li>"; echo "<li>"; the_title(); echo"</li>"; } 

and for product category page

 if (is_tax()) { $posts_page_id = get_option('page_for_posts'); $posts_page_url = get_permalink($posts_page_id); echo '<li>';$bar = "Shopping"; if(get_option_tree('blog_name', '', false)) echo "<a href=".home_url()."/shopping/>$bar</a> > </li>" ; echo "<li>"; woocommerce_page_title(); echo"</li>";} 

I commented on the line that gets the name blog_name, because I use a custom page for my store, and not the default for woocommerce. I don’t know if there is another way to do this, but I notice that most of the code in this topic is not very professional even in css widgets, it was a bad choice.

+1
source

I debugged this and, unfortunately, Woocommerce (version 2.3.8) does not use any bindings to directly configure the breading array. Therefore, if you want to change the displayed patches without changing the permalink structure, it is best to copy the breadcrumbs template file from the plugin ( /woocommerce/templates/global/breadcrumb.php ) to your theme ( /theme_name/woocommerce/global/ ) and add code to include links before exiting the loop begins. I only do this for product categories, tags, and parts, but you can add other conventions if you want.

 <?php /** * Shop breadcrumb * * @author WooThemes * @package WooCommerce/Templates * @version 2.3.0 * @see woocommerce_breadcrumb() */ if ( ! defined( 'ABSPATH' ) ) { exit; } if ( $breadcrumb ) { // add shop home url to breadcrumbs if( is_product_category() || is_product_tag() || is_product() ) { $shop_page_id = wc_get_page_id( 'shop' ); $shop_home_arr = array( get_the_title($shop_page_id), get_permalink($shop_page_id)); // insert to breadcrumbs array on second position array_splice($breadcrumb, 1, 0, array($shop_home_arr)); } echo $wrap_before; foreach ( $breadcrumb as $key => $crumb ) { echo $before; if ( ! empty( $crumb[1] ) && sizeof( $breadcrumb ) !== $key + 1 ) { echo '<a href="' . esc_url( $crumb[1] ) . '">' . esc_html( $crumb[0] ) . '</a>'; } else { echo esc_html( $crumb[0] ); } echo $after; if ( sizeof( $breadcrumb ) !== $key + 1 ) { echo $delimiter; } } echo $wrap_after; } 
+8
source

This can be made much simpler. You just need to change the permalink settings - as stated on github in question 3145 :

Check out these criteria:

 // If permalinks contain the shop page in the URI prepend the breadcrumb with shop if ( $shop_page_id && strstr( $permalinks['product_base'], '/' . $shop_page->post_name ) && get_option( 'page_on_front' ) !== $shop_page_id ) { $prepend = $before . '<a href="' . get_permalink( $shop_page ) . '">' . $shop_page->post_title . '</a> ' . $after . $delimiter; } 

Otherwise, it was never added.

To apply this, go to:

β†’ WordPress operating system β†’ Settings β†’ Permalink

And set the woocommerce permalink options to one of the following:

  • Base stores
  • Shop with category
  • User base

If the latter is used, then the ingot "/ shop / ..." should be added.

There is a problem 6584 :

Warning: preg_match (): Unknown modifier 't' in wc-core-functions.php on line 533

What, for example, occurs if the "User base" looks like this: "/ shop / product / ...". There is a commit that fixed it, available in master, but not 2.2.8.

The slug part store can be replaced by something else, for example, something localized.

+4
source

For those who encounter this in 2019, there is a much simpler way to add an item after the β€œhome” crumb if you do not want to change permalinks or edit theme files. This may not be the perfect solution, but it worked for me.

The WC_Breadcrumb class filters breadcrumbs before it returns them, and we can plug in and modify the array. The $ crumbs array is just an array [[title, url], [title, url]]

 add_filter( 'woocommerce_get_breadcrumb', function($crumbs, $Breadcrumb){ $shop_page_id = wc_get_page_id('shop'); //Get the shop page ID if($shop_page_id > 0 && !is_shop()) { //Check we got an ID (shop page is set). Added check for is_shop to prevent Home / Shop / Shop as suggested in comments $new_breadcrumb = [ _x( 'Shop', 'breadcrumb', 'woocommerce' ), //Title get_permalink(wc_get_page_id('shop')) // URL ]; array_splice($crumbs, 1, 0, [$new_breadcrumb]); //Insert a new breadcrumb after the 'Home' crumb } return $crumbs; }, 10, 2 ); 
+1
source

I stumbled upon this thread, as I still could not get support. I created a custom store page, and therefore my woocommerce product page in the settings is empty.

My breadcrumbs work for (home icon)> Online Store> My Cart> Checkout in the store, however, when I click on the product, it deletes part of the online store, and so I just see (home icon)> [empty space ]> Product Name

Where can I enter CSS and what code can I enter to make a link [space] to my online store.

Thanks! Suzy

0
source

Source: https://habr.com/ru/post/1490319/


All Articles