I have a WooCommerce shop that holds variable products.
I want to create some sort of export (on a page) that shows me all products including variations in a table.
I am viewing all products and created a loop to get the variations but it only shows me one product variation.
<?php
/*
Template Name: Store Management
*/
if (!is_user_logged_in() || !current_user_can('manage_options')) wp_die('This page is private.');
// Get
$args = array(
'post_type' => 'product',
'numberposts' => -1,
);
$products = get_posts( $args );
echo '<pre>';
print_r($products);
echo '</pre>';
foreach($products as $product):
$args = array(
'post_parent' => $plan->ID,
'post_type' => 'product_variation',
'numberposts' => -1,
);
$product = wc_get_product( $product->ID );
$variations = $product->get_available_variations();
echo '<pre>';
print_r($variations);
echo '</pre>';
endforeach;
?>
Can anyone tell me how to get all variations for all products?
M.