Woocommerce 标签档案面包屑

问题描述 投票:0回答:2

我想在 woocommerce 标签存档页面(例如 website.com/product-tag/jesse-marsh/)上显示面包屑。

面包屑目前在 woocommerce 产品和类别页面上可见。我不知道在哪里添加代码才能使面包屑在标签存档页面上可见。

有什么建议吗?谢谢!

woocommerce tags breadcrumbs
2个回答
0
投票

这是在不更改核心文件的情况下执行此操作的方法:

add_filter('woocommerce_get_breadcrumb', 'change_woocommerce_breadcrumb', 10, 2);
function change_woocommerce_breadcrumb($crumbs, $breadcrumb)
{
    //$crumbs[0] would be the home url or shop url
    //crumbs[1] would be the current tag (tags are non-hirarchical)
    //$crumbs[1][0] would be the tag url, which should be empty as we are already on the tag page
    //crumbs[1][1] would be the tag name
    //use var_dump($crumbs); to see your structure of the crumbs
    if (is_product_tag()) {
        $tag = get_queried_object();
        $tag_name = $tag->name;
        $crumbs[1][0] = $tag_name;
        //you could also do something like this:
        //$crumbs[1][0] = sprintf(_e('The name of the tag is %s','yourtextdomain'),$tag_name);

    }
    return $crumbs;
}

-1
投票

我必须编辑 woocommerce 插件:

wp-content/plugins/woocommerce/includes/class-wc-breadcrumb.php

/**
 * Product tag trail.
 */
private function add_crumbs_product_tag() {
    $current_term = $GLOBALS['wp_query']->get_queried_object();

    $this->prepend_shop_page();


    //$this->add_crumb( sprintf( __( 'Products tagged “%s”', 'woocommerce' ), $current_term->name ) );

    $this->add_crumb( sprintf('%s', $current_term->name ) );
}
© www.soinside.com 2019 - 2024. All rights reserved.