问题描述
主页> example1> example2 > example3
example2将转到/ product-category / products / example2 /,但我需要 使用自定义页面修改此链接:例如 / mypersonalproducts / mypage
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 (将#修改为@)