I'm redesigning my website and am having trouble with the breadcrumbs. I would like to replace the product category with the page number which the currently selected product originated from. So instead of: Home > Shop > abstract > product name I would like: Home > Shop > Page 3 > product name
The reason for this is my site is used for displaying/selling my art and the product category in the breadcrumb just doesn't make sense. I would like the customer to be able to return to the page they came from and not a new page of products that happen to be in the same category.
My site is https://dev.paulruskin.com and I'm using the Storefront theme in WordPress.
I have searched extensively on here and googled the heck out of it but can't seem to find a good enough example.
Any help will be greatly appreciated.
EDIT:
So this is what I came up with so far.
add_filter( 'woocommerce_get_breadcrumb', 'custom_breadcrumb', 10, 2 );
function custom_breadcrumb( $crumbs ) {
$url = $_SERVER['HTTP_REFERER'];
$url_array = array_values( explode("/", $url) );
$pg_num = $url_array[count($url_array) -2];
if ( strpos( $url, '/page/') !== false ) {
foreach( $crumbs as $key => $crumb ) {
$taxonomy = 'product_cat';
$term_array = term_exists( $crumb[0], $taxonomy );
if ( $term_array !== 0 && $term_array !== null ) {
$crumbs[$key][0] = "Page " . $pg_num;
$crumbs[$key][1] = $url;
}
}
}
return $crumbs;
}'
This only partially works. What I realized is if the user clicks the prev or next buttons then the previous url won't still list the page number.
Is there a way to get the page number from Woocommerce or WordPress that a product belongs to?
You could add a link on top of the breadcrumbs to go back to previous page:
<a href="#" onclick="window.history.go(-1); return false;">Back to previous page</a>
This is the same as clicking the browsers back button.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.