【问题标题】:Add the sku to order items on my account order view pages in Woocommerce在 Woocommerce 的我的帐户订单视图页面上添加 sku 以订购商品
【发布时间】:2019-04-10 02:41:29
【问题描述】:

在 Woocommerce 中,我在 MyAccount 中自定义查看顺序。我已经用这个答案代码添加了产品图片:Add the product image to Woocommerce my account order view

现在我想将产品 SKU 添加到 The View 订单页面,但我不知道如何获取。

有人有想法吗?

【问题讨论】:

  • 如果您不更改 stackOverFlow 答案代码,请将链接添加到您的问题。无论如何,在使用现有答案线程时,您应该始终在您的问题中添加链接。

标签: php wordpress woocommerce orders sku


【解决方案1】:

用以下代码替换您的代码以在订单商品中显示产品 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;
}

代码进入您的活动子主题(活动主题)的 function.php 文件中。它应该可以工作。

【讨论】:

    猜你喜欢
    • 2018-11-28
    • 2015-03-19
    • 1970-01-01
    • 1970-01-01
    • 2019-03-17
    • 2019-07-14
    • 2019-01-21
    • 1970-01-01
    • 2013-04-20
    相关资源
    最近更新 更多