1

使用 Woocommerce,我想在我的帐户 /my-account/view-order/[orderid]/ 的订单视图页面中添加 SKU 而不是产品名称

我可以使用下面的代码添加带有链接的 SKU。SKU 显示在同一行的产品名称之后。

add_filter( 'woocommerce_order_item_name', 'display_sku_in_order_item', 20, 3 );
function display_sku_in_order_item( $item_name, $item, $is_visible ) {
    if( is_wc_endpoint_url( 'view-order' ) ) {
        $product   = $item->get_product(); 
        if( $sku = $product->get_sku() )
            $item_name .= '<a href="' . $product->get_permalink() . '" class="product-sku">' . __( "Product ", "woocommerce") . $sku . '</a>';
    }
    return $item_name;
}

但是,我想删除产品名称,但我不知道为此编写的代码。请问有什么帮助吗?

4

1 回答 1

1

您只需要在代码中替换$item_name .=by $item_name =,例如:

add_filter( 'woocommerce_order_item_name', 'display_sku_in_order_item', 20, 3 );
function display_sku_in_order_item( $item_name, $item, $is_visible ) {
    if( is_wc_endpoint_url( 'view-order' ) ) {
        $product   = $item->get_product(); 
        if( $sku = $product->get_sku() )
            $item_name = '<a href="' . $product->get_permalink() . '" class="product-sku">' . __( "Product ", "woocommerce") . $sku . '</a>';
    }
    return $item_name;
}

代码位于您的活动子主题(或活动主题)的 function.php 文件中。它应该工作。

于 2019-04-28T09:40:16.707 回答