java商城购物车商品sku变化,在Woocommerce 3中的购物车和结帐页面上显示SKU

I would like to display SKU on cart (Under product column ) and checkout page.

I searched SO, but all answers are for old versions of WooCommerce and non of them is for 3.x.

How can I show SKU on cart and checkout pages in Woocommerce 3?

解决方案

You can do it with a custom unction hooked in woocommerce_cart_item_name action hook, this way:

add_filter( 'woocommerce_cart_item_name', 'showing_sku_in_cart_items', 99, 3 );

function showing_sku_in_cart_items( $item_name, $cart_item, $cart_item_key ) {

// The WC_Product object

$product = $cart_item['data'];

// Get the SKU

$sku = $product->get_sku();

// When sku doesn't exist

if(empty($sku)) return $item_name;

// Add the sku

$item_name .= '' . __( "SKU: ", "woocommerce") . $sku . '';

return $item_name;

}

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

This code is tested and works on WooCommerce 3+. You will get:

NDx5U.png

And

wG6CG.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值