Im trying to get the correct price for each item variation however it only seems to be getting the first price of that product variation. Not sure how to solve this.
Code:
$query = new WC_Order_Query( array(
'status' => 'on-hold',
'orderby' => 'date',
'order' => 'DESC',
'return' => 'ids',
) );
$order_ids = $query->get_orders();
foreach( $order_ids as $order_id ) {
$order = new WC_Order($order_id);
foreach ($order->get_items() as $item_id => $item_obj) {
$_product = wc_get_product($item_obj['product_id']);
$product = new WC_Product_Variable($item_obj['product_id']);
$product_variations = $product->get_available_variations();
$variation_product_id = $product_variations [0]['variation_id'];
$variation_product = new WC_Product_Variation( $variation_product_id );
$t_dy = $variation_product->get_price();
$item_qty = $item_obj['qty'];
$it_total = $item_qty * $t_dy;
$td = wc_update_order_item_meta($item_id, '_line_total', $it_total);
$order->calculate_totals();
$order->save();
}
}