Replace the product name by the Sku in My account view order pages

别说谁变了你拦得住时间么 提交于 2019-12-07 23:46:25

You just need to replace $item_name .= by $item_name = in your code, like:

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;
}

Code goes in function.php file of your active child theme (or active theme). It should work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!