[英]Add the sku to order items on my account order view pages in Woocommerce
In Woocommerce, I am customizing my view order in MyAccount.在 Woocommerce 中,我正在 MyAccount 中自定义查看顺序。 I already added the Product images with this answer code: Add the product image to Woocommerce my account order view
我已经使用此答案代码添加了产品图片: 将产品图片添加到 Woocommerce 我的帐户订单视图
Now I would like to add the Product SKU to The View order pages but, I don't know how to get it.现在我想将产品 SKU 添加到查看订单页面,但我不知道如何获取。
Anyone have an Idea?有人有想法吗?
Replacing your code with the following to display the product SKU in order items:用以下代码替换您的代码以在订单项中显示产品 SKU:
// Display the product thumbnail in order view pages
add_filter( 'woocommerce_order_item_name', 'display_product_image_in_order_item', 20, 3 );
function display_product_image_in_order_item( $item_name, $item, $is_visible ) {
// Targeting view order pages only
if( is_wc_endpoint_url( 'view-order' ) ) {
$product = $item->get_product(); // Get the WC_Product object (from order item)
$thumbnail = $product->get_image(array( 36, 36)); // Get the product thumbnail (from product object)
// The thumbnail
if( $product->get_image_id() > 0 )
$item_name = '<div class="item-thumbnail">' . $thumbnail . '</div>' . $item_name;
// The SKU
if( $sku = $product->get_sku() )
$item_name .= '<br><div class="product-sku">' . $sku . '</div>';
}
return $item_name;
}
Code goes in function.php file of your active child theme (active theme).代码位于活动子主题(活动主题)的 function.php 文件中。 It should works.
它应该有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.