我已经使用了这个代码,我几乎得到了我的结果,但我也想在航运类前面显示运费。谁能修改这段代码?谢谢
add_filter( 'woocommerce_cart_item_name', 'shipping_class_in_item_name', 10, 3);
function shipping_class_in_item_name( $item_name, $cart_item, $cart_item_key ) {
$product = $cart_item['data'];
$shipping_class_id = $product->get_shipping_class_id();
$shipping_class_term = get_term( $shipping_class_id, 'product_shipping_class' );
if( empty( $shipping_class_id ) )
return $item_name;
$label = __( 'Shipping', 'woocommerce' );
return $item_name . '<br>
<p class="item-shipping_class">
<strong>' .$label . ': </strong>' . $shipping_class_term->name . '</p>';
}
尝试添加这个:
$shipping_cost = wc()->cart->get_cart_item_data($cart_item);