Created
November 6, 2018 09:58
-
-
Save danichim/09591c25c5d706fb9b9ce28aaf206fdc to your computer and use it in GitHub Desktop.
Loop through WooCommerce order products
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
$filters = array( | |
'post_status' => 'any', | |
'post_type' => 'shop_order', | |
'posts_per_page' => 200, | |
'paged' => 1, | |
'orderby' => 'modified', | |
'order' => 'ASC' | |
); | |
$loop = new WP_Query($filters); | |
while ($loop->have_posts()) { | |
$loop->the_post(); | |
$order = new WC_Order($loop->post->ID); | |
foreach ($order->get_items() as $key => $lineItem) { | |
//uncomment the following to see the full data | |
// echo '<pre>'; | |
// print_r($lineItem); | |
// echo '</pre>'; | |
echo '<br>' . 'Product Name : ' . $lineItem['name'] . '<br>'; | |
echo 'Product ID : ' . $lineItem['product_id'] . '<br>'; | |
if ($lineItem['variation_id']) { | |
echo 'Product Type : Variable Product' . '<br>'; | |
} else { | |
echo 'Product Type : Simple Product' . '<br>'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment