If you're doing a WooCommerce integration you'll definitely need to get the SKU numbers for the products in an order.

You can use this sample code to list the skus for a given order. We tested this as a system plugin but you need to copy the contents of the function and adapt it for your needs.


// Blog post: https://orbisius.com/4904
// example.com/?orb_blog_post4904_list_order_item_sku
if (!isset($_REQUEST['orb_blog_post4904_list_order_item_sku'])) {

add_action('init', 'orb_blog_post4904_list_order_item_sku');

function orb_blog_post4904_list_order_item_sku() {
	$order = wc_get_order(322);

	foreach ($order->get_items() as $item) {
		$product_obj = $item->get_product();
		$product_sku = $product_obj ? $product_obj->get_sku() : '';
		echo "product_sku: $product_sku\n<br/>";


The get_product() method will pull the variation's sku which is what we needed. If you need to get the something from the parent product see the code below.

if ( $product_obj->is_type( 'variation' ) ) {
		$product_obj = wc_get_product( $item->get_product_id() );