Custom breadcrumbs fail with cache
-
Some products in my woocommerce is assigned to multiple categories.
To have the breadcrumbs always show the category the user came to the product from,
I have custom code in /public/wp-content/themes/flatsome-child/woocommerce/global/breadcrumb.php. Code found below.This works very well until I turn on the cache function in wp fastest cache. When the cache is turned on, the breadcrumb is not correct. If a product first is visited from category A, then B, breadcrumb is still showing category A instead of B.
I have tried excluding breadcrumb.php without that helping (exclude contains: breadcrumb.php. https://kamerasenteret.no/(.*)breadcrumb.php(.*))
Example product: Adapterkabel for Valtra Smart Touch og MF-skjerm
Can be found in these categories:
https://kamerasenteret.no/kategori/landbruk/valtra/
https://kamerasenteret.no/kategori/landbruk/massey-ferguson/breadcrumb.php:
<?php
/**
* Shop breadcrumb
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.3.0
* @see woocommerce_breadcrumb()
*/if ( ! defined( ‘ABSPATH’ ) ) {
exit;
}if (get_post_type() == ‘product’ && is_single() && ! is_attachment()) {
echo ‘Hjem ‘. ‘ / Nettbutikk / ‘ ;if ($terms = get_the_terms($post->ID, ‘product_cat’)) {
$referer = wp_get_referer();
foreach ($terms as $term) {
$referer_slug = (strpos($referer, $term->slug));if ($referer_slug == true) {
$category_name = $term->name;
$ancestors = get_ancestors($term->term_id, ‘product_cat’);
$ancestors = array_reverse($ancestors);
foreach ($ancestors as $ancestor) {
$ancestor = get_term($ancestor, ‘product_cat’);if (! is_wp_error($ancestor) && $ancestor) {
echo $before . ‘ slug, ‘product_cat’) . ‘”> ‘ . $ancestor->name . ‘ ‘ . $after . $delimiter;
}
}
echo $before . ‘ slug, ‘product_cat’) . ‘”> ‘ . $category_name . ‘ ‘ . $after ;
}
}
}// echo $before .’slug, ‘product_cat’) . ‘”>’ . $category_name . ‘‘ . $after;
}else{
foreach ( $breadcrumb as $key => $crumb ) {
//echo “";print_r($crumb);echo "
“;
echo $before;if ( ! empty( $crumb[1] ) && sizeof( $breadcrumb ) !== $key + 1 ) {
echo ‘‘ . esc_html( $crumb[0] ) . ‘‘;
//echo $unique_bc;
} else if(!is_product() && !flatsome_option(‘wc_category_page_title’)) {
echo esc_html( $crumb[0] );
//echo ‘‘ . esc_html( $crumb[0] ) . ‘‘;
}echo $after;
// Single product or Active title
if(is_product() || flatsome_option(‘wc_category_page_title’)){
$key = $key+1;
if ( sizeof( $breadcrumb ) > $key+1) {
echo ‘ <span class=”divider”>’.$delimiter.'</span> ‘;
}
} else{// Category pages
if ( sizeof( $breadcrumb ) !== $key + 1 ) {
echo ‘ <span class=”divider”>’.$delimiter.'</span> ‘;
}
}}
echo $wrap_after;
do_action(‘flatsome_after_breadcrumb’);
}// if ( ! defined( ‘ABSPATH’ ) ) {
// exit;
// }// if ( ! empty( $breadcrumb ) ) {
// echo $wrap_before.’ ‘;
// foreach ( $breadcrumb as $key => $crumb ) {
// echo $before.’ ‘;
// if ( ! empty( $crumb[1] ) && sizeof( $breadcrumb ) !== $key + 1 ) {
// echo ‘ ‘ . esc_html( $crumb[0] ) . ‘ ‘;
// } else {
// if ( !is_product() ) {
// echo esc_html( $crumb[0] );
// } else {
// echo ‘ ‘; // if is a product page it doesn’t display the page crumb…
// }
// }// echo $after;
// if ( sizeof( $breadcrumb ) !== $key + 1 ) {
// echo $delimiter;
// }// }
// echo $wrap_after;
// }
The page I need help with: [log in to see the link]
- The topic ‘Custom breadcrumbs fail with cache’ is closed to new replies.