Skip to content

Instantly share code, notes, and snippets.

@stinGeorge
Forked from corsonr/functions.php
Created February 18, 2021 14:38
Show Gist options
  • Save stinGeorge/d0eecb98c0c5caf1d074af8ce9aae61b to your computer and use it in GitHub Desktop.
Save stinGeorge/d0eecb98c0c5caf1d074af8ce9aae61b to your computer and use it in GitHub Desktop.
Loop through WooCommerce order products
<?php
$count = 1;
foreach( $order->get_items() as $item_id => $line_item ){
$item_data = $line_item->get_data();
$product = $line_item->get_product();
$product_name = $product->get_name();
$item_quantity = $line_item->get_quantity();
$item_total = $line_item->get_total();
$metadata['Line Item '.$count] = 'Product name: '.$product_name.' | Quantity: '.$item_quantity.' | Item total: '. number_format( $item_total, 2 );
$count += 1;
}
return $metadata;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment