简体   繁体   English

在 Woocommerce 的我的帐户订单视图页面上添加 sku 以订购商品

[英]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.

相关问题 在我的帐户查看订单页面中用 Sku 替换产品名称 - Replace the product name by the Sku in My account view order pages 在 WooCommerce 中编辑我的帐户订单视图页面 - Editing My account Order view pages in WooCommerce 在WooCommerce我的帐户查看订单页面上的订单详细信息下添加自定义文本 - Add custom text under order details on WooCommerce My account view order pages 在 Woocommerce 中按 SKU 对订单项进行排序 - Sorting order items by SKU in Woocommerce WooCommerce -Thankyou 和“我的帐户”查看订单页面上的自定义通知 - WooCommerce - Custom notice on Thankyou and "My account" view order pages 在 Woocommerce 3 中的我的帐户订单查看页面上显示付款说明 - Display payment instructions on my account order view pages in Woocommerce 3 根据产品 SKU 为 WooCommerce 订单项目添加随机字符串 - Add random string to WooCommerce order items based on product SKU 在WooCommerce上添加支付订单按钮我的账户查看订单挂单 - Add a pay order button on WooCommerce My account view order for pending orders 在Woocommerce中检查并显示所有具有SKU的订单商品 - Check and display all Order items that have a SKU in Woocommerce 在 WooCommerce 我的帐户中更改标题自定义“查看订单”端点 - Change title custom "view-order" endpoint in WooCommerce My account
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM