I’m trying to get the COST of a line item in the WC order backend. (Seen in the attached image:
Online I’ve read that I can do this, but all that seems to do is print out my line item total. I can’t seem to find a cost function. Any ideas? Thanks!
$orderLineItems = $order->get_items();
/* @var $order_item WC_Order_Item_Product */
foreach ($orderLineItems as $item_id => $order_item) {
var_dump($order_item->get_total());
}
2
Answers
You can get the cost by dividing the total with the quantity.
Try this
You can get the cost by order item.