在Woocommerce 3中的购物车和结帐页面上显示SKU [英] Show SKU on cart and checkout pages in Woocommerce 3

查看:63
本文介绍了在Woocommerce 3中的购物车和结帐页面上显示SKU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在购物车(在产品列下)和结帐页面上显示SKU。



我搜索了SO,但所有答案都是针对WooCommerce的旧版本和非



如何在Woocommerce 3中在购物车和结帐页面上显示SKU?

解决方案


2020更新:




相关类似:如何在收到订单页面和电子邮件订单中显示带有产品标题的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?

解决方案

2020 Update: How display product SKU directly under item name in WooCommerce?

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 .= '<br><small class="product-sku">' . __( "SKU: ", "woocommerce") . $sku . '</small>';

    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:

And

Related similar: How to Show SKU with product title in Order received page and Email order

这篇关于在Woocommerce 3中的购物车和结帐页面上显示SKU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆