foreach ( $order->get_items() as $item_id => $item ) {
$product = $order->get_product_from_item( $item );
$product_id = null;
$product_sku = null;
// Check if the product exists.
if ( is_object( $product ) ) {
$product_id = ( isset( $product->variation_id ) ) ? $product->variation_id : $product->id;
$product_sku = $product->get_sku();
}
$dp = 2; // округление
$order_data['line_items'][] = array(
'id' => $item_id,
'subtotal' => wc_format_decimal( $order->get_line_subtotal( $item, false, false ), $dp ),
'subtotal_tax' => wc_format_decimal( $item['line_subtotal_tax'], $dp ),
'total' => wc_format_decimal( $order->get_line_total( $item, false, false ), $dp ),
'total_tax' => wc_format_decimal( $item['line_tax'], $dp ),
'price' => wc_format_decimal( $order->get_item_total( $item, false, false ), $dp ),
'quantity' => wc_stock_amount( $item['qty'] ),
'name' => $item['name'],
'product_id' => $product_id,
'sku' => $product_sku,
);
}