在Woocommerce 3中的购物车和结帐页面上显示SKU [英] Show SKU on cart and checkout pages in Woocommerce 3
问题描述
我想在购物车(在产品列下)和结帐页面上显示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屋!