I am printing a stock/inventory report from WooCommerce. How can I echo the products variations i.e. product color or size, etc?
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$product = new WC_Product_Variation( $loop->post->ID );
?>
<tr>
<td><?php echo $product->get_title(); ?></td>
<td><?php echo get_the_title( $loop->$product->get_attributes ); ?></td>
<td><?php echo $product->sku; ?></td>
<td><?php echo $product->stock; ?></td>
</tr>
<?php
endwhile;
I have tried the following but I get something like: Variation #49379
<?php echo get_the_title( $loop->get_post_meta( $thepostid, '_product_attributes', true ) ); ?>
You can use:
echo $product->get_available_variations();
If this is a single style template, make sure you add global $product; near the top.