user13371545
user13371545

Reputation:

How to change the name in the breadcrumbs woocommerce attribute?

Tell me, how can I change the title in the breadcrumbs of the "Attribute" parameter?

I use the Woocommerce plugin. There is an attribute name, there is an attribute value. (Delete one word)

At the moment, the path is this:

product "attribute name" / "attribute value"

Need the following path:

"attribute name" / "attribute value"

Upvotes: 1

Views: 931

Answers (1)

2caffe
2caffe

Reputation: 51

I think there is not a specific filter for doing that, so I had to do it in a dirty way. There is a filter "woocommerce_get_breadcrumb" that gives you the opportunity to edit the breadcrumb before is shown. The crumbs are arrays [0]=>Label [1]=>URL

I added a function in my functions.php:

function er_woocommerce_get_breadcrumbs($crumbs, $breadcrumb) {
    foreach ($crumbs as &$crumb) {
        $cantina = false;
        foreach ($crumb as &$v) {
            if (substr($v, 0, 9) === "Prodotto ") {
               // case index = 0
               $cantina = true;
               $v = substr($v, 9);
            }
            if (strlen($v) === 0) {
               // case index = 1
                $cantina = false;
                $v = "/cantine";
            }
        }
    }
    return $crumbs;
}

add_filter('woocommerce_get_breadcrumb', 'er_woocommerce_get_breadcrumbs', 9999, 2);

The shop is only in italian, so I didn't need to care multilingual matters. The word to remove in my case is "Prodotto ".

In the first part of the function I removed the word "Prodotto ", while in the second part I added the link to a custom page.

The result is here: https://enotecarizzi.it/cantina/col-dorcia/

Upvotes: 2

Related Questions