Reputation: 157
Using Woocommerce, I would like to add the SKU instead of the product name in the thank you page and order pages like in Order received (thankyou) and Order pay pages.
I use the woocommerce_cart_item_name
filter hook like in this previous thread, but it works only My account > View order pages.
I have also tried to use woocommerce_add_order_item_meta
filter hook, but it doesn't work.
Can I know the correct complete code to add to function.php
to be able to replace the product name by the SKU in Order received (thankyou) and Order pay pages.
Upvotes: 1
Views: 627
Reputation: 253901
To replace the product name by the SKU on Order received, Order pay (and my account Order view) pages, you need to use the following:
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() ) {
$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). Tested and work.
Related: Woocommerce conditional tags reference
Upvotes: 1