我在购物车页面中显示带有产品标题的 SKU 值,但现在每个单词 SKU 和产品标题都单独链接。我怎样才能只显示单个链接而不是单独链接。
用于在购物车页面中显示 SKU 值在 Functions.php中添加了此代码
add_filter( 'woocommerce_cart_item_name', 'add_sku_in_cart', 20, 3);
function add_sku_in_cart( $title, $values, $cart_item_key ) {
$sku = $values['data']->get_sku();
$url = $values['data']->get_permalink( $product->ID );
$final='<a href="'. $url .'">SKU: '. $sku .'</a>';
return $title ? sprintf("%s - ", $final) .$title : $final;
}
示例 现在显示这个
<a href="http://localhost/test/?product=child-product">SKU: asda121 </a> - <a href="http://localhost/test/?product=child-product">Child Product</a>
但我想要那样
<a href="http://localhost/test/?product=child-product">SKU: asda121 - Child Product</a>