微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何更改Woocommerce面包屑中的一个链接?

如何解决如何更改Woocommerce面包屑中的一个链接?

我需要更改woocommerce面包屑中的一个链接

主页> example1> example2 > example3

example2将转到/ product-category / products / example2 /,但我需要 使用自定义页面修改链接:例如 / mypersonalproducts / mypage

我尝试在wordpress中使用“代码片段”插件

add_filter( 'woocommerce_get_breadcrumb','custom_get_breadcrumb',20,2 );
function custom_get_breadcrumb( $crumbs,$breadcrumb ){
    if( ! is_shop() ) return $crumbs; // Only shop page

    // The Crump item to target
    $target = __( 'example2','woocommerce' );

    foreach($crumbs as $key => $crumb){
        if( $target === $crumb[0] ){
            // 1. Change name
            $crumbs[$key][0] = __( 'Name','woocommerce' );

            // 2. Change URL (you can also use get_permalink( $id ) with the post Id
            $crumbs[$key][1] = home_url( '/mypersonalproducts/mypage' );
        }
    }
    return $crumbs;
}

这:

add_filter( 'woocommerce_get_breadcrumb','custom_breadcrumb',10,2 );
function custom_breadcrumb( $crumbs,$object_class ){
    // Loop through all $crumb
    foreach( $crumbs as $key => $crumb ){
        $taxonomy = 'product_cat'; // The product category taxonomy

        // Check if it is a product category term
        $term_array = term_exists( $crumb[0],$taxonomy );

        // if it is a product category term
        if ( $term_array !== 0 && $term_array !== null ) {

            // Get the WP_Term instance object
            $term = get_term( $term_array['example2'],$taxonomy );

            // HERE set your new link with a custom one
            $crumbs[$key][1] = home_url( '/mypersonalproducts/mypage' ); // or use all other dedicated functions
        }
    }

    return $crumbs;
}

但这没用

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。