Created
December 4, 2015 20:09
-
-
Save eristic/5be6bff0d9c569335cee to your computer and use it in GitHub Desktop.
Grab the SKU by looping through the items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$items = $order->get_items(); | |
// Loop through ordered items | |
foreach ($items as $item) { | |
$product_name = $item['name']; | |
$product_id = $item['product_id']; | |
$product_variation_id = $item['variation_id']; | |
// Check if product has variation. | |
if ($product_variation_id) { | |
$product = new WC_Product($item['variation_id']); | |
} else { | |
$product = new WC_Product($item['product_id']); | |
} | |
// Get SKU | |
$sku = $product->get_sku(); | |
// Echo SKU | |
echo "<h2>SKU: "; | |
echo $sku; | |
echo "</h2>"; | |
} // end foreach |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment