Reputation: 1
Woocommerce displays individual item price in checkout, but not in order confirmations.
I don't need it to display a new column. Something simple like ($x.xx each)
after the item name.
All of my pricing is based off variations, so I modified the code below to display variation descriptions, then I manually enter the "$x.xx each" as the description. It should be pretty easy to modify this to display price instead, but I can't seem to figure it out.
I just need to know how to change $_var_description
to show price instead of description. Thanks!
add_filter('woocommerce_order_item_name', 'display_product_title_as_link', 10, 2);
function display_product_title_as_link($item_name, $item)
{
$_product = get_product($item['variation_id'] ? $item['variation_id'] : $item['product_id']);
$link = get_permalink($_product->id);
$_var_description = '';
if ($item['variation_id']) {
$_var_description = $_product->get_variation_description();
}
if ($_var_description) {
return '' . $item_name . ' (' . $_var_description . ')';
} else {
return '' . $item_name;
}
}
Expected results is on order confirmations it will say Item name + individual price instead of item name.
Upvotes: 0
Views: 317
Reputation: 134
add_filter( 'woocommerce_order_item_name', 'add_price_in_item_title', 10, 2 );
function add_price_in_item_title( $item_name, $item ) {
$order = $item->get_order();
$item_price = wc_price( ($item->get_total()/ $item->get_quantity()), array( 'currency' => $order->get_currency() ) );
if( ($item->get_total()/ $item->get_quantity()) ) {
return $item_name . ' (' . $item_price . ')';
} else {
return $item_name;
}
}
I change a bit itzmekhokan code and use this on my web, and it's work show single price on checkout page
Upvotes: 0
Reputation: 2770
Add the follows code snippet to do the above -
add_filter( 'woocommerce_order_item_name', 'add_price_in_item_title', 10, 2 );
function add_price_in_item_title( $item_name, $item ) {
$order = $item->get_order();
$item_price = wc_price( $item->get_total(), array( 'currency' => $order->get_currency() ) );
if( $item->get_total() ) {
return $item_name . ' (' . $item_price . ')';
} else {
return $item_name;
}
}
Upvotes: 1