Skip to content

Instantly share code, notes, and snippets.

@eristic
Created December 4, 2015 20:09
Show Gist options
  • Save eristic/5be6bff0d9c569335cee to your computer and use it in GitHub Desktop.
Save eristic/5be6bff0d9c569335cee to your computer and use it in GitHub Desktop.
Grab the SKU by looping through the items
$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