wc get all items of order code example
Example: wc order items
$order = wc_get_order($order_id);
foreach ($order->get_items() as $item_key => $item ):
$item_id = $item->get_id();
$product = $item->get_product();
$product_id = $item->get_product_id();
$variation_id = $item->get_variation_id();
$item_type = $item->get_type();
$item_name = $item->get_name();
$quantity = $item->get_quantity();
$tax_class = $item->get_tax_class();
$line_subtotal = $item->get_subtotal();
$line_subtotal_tax = $item->get_subtotal_tax();
$line_total = $item->get_total();
$line_total_tax = $item->get_total_tax();
$item_data = $item->get_data();
$product_name = $item_data['name'];
$product_id = $item_data['product_id'];
$variation_id = $item_data['variation_id'];
$quantity = $item_data['quantity'];
$tax_class = $item_data['tax_class'];
$line_subtotal = $item_data['subtotal'];
$line_subtotal_tax = $item_data['subtotal_tax'];
$line_total = $item_data['total'];
$line_total_tax = $item_data['total_tax'];
$product = $item->get_product();
$product_type = $product->get_type();
$product_sku = $product->get_sku();
$product_price = $product->get_price();
$stock_quantity = $product->get_stock_quantity();
endforeach;