1 回答
TA贡献1848条经验 获得超2个赞
以下将在购物车和结帐页面中的购物车项目名称下显示自定义文本,用于定义的运输类别:
// Display a custom text under cart item name in cart page
add_filter( 'woocommerce_cart_item_name', 'custom_text_cart_item_name', 10, 3 );
function custom_text_cart_item_name( $item_name, $cart_item, $cart_item_key ) {
// Here below define your shipping class slug
$shipping_class = 'extra';
if( is_cart() && $cart_item['data']->get_shipping_class() === $shipping_class ) {
$item_name .= '<br /><div class="item-shipping-class">' . __("This is my custom text", "woocommerce") . '</div>';
}
return $item_name;
}
// Display a custom text under cart item name in checkout
add_filter( 'woocommerce_checkout_cart_item_quantity', 'custom_checkout_text_cart_item_name', 10, 3 );
function custom_checkout_text_cart_item_name( $item_qty, $cart_item, $cart_item_key ) {
// Here below define your shipping class slug
$shipping_class = 'extra';
if( $cart_item['data']->get_shipping_class() === $shipping_class ) {
$item_qty .= '<br /><div class="item-shipping-class">' . __("This is my custom text", "woocommerce") . '</div>';
}
return $item_qty;
}
代码位于活动子主题(或活动主题)的 functions.php 文件中。测试和工作。
- 1 回答
- 0 关注
- 130 浏览
添加回答
举报