PHP Woocommerce get product variations

   
<?php
    $product_id = $product->ID;
    $product_sku = get_post_meta($product_id, '_sku', true);
    $product_variations = get_posts(array(
        'post_type' => 'product_variation',
        'posts_per_page' => -1,
        'post_status' => 'publish',
        'post_parent' => $product_id,
        'meta_query' => array(
            array(
                'key' => '_sku',
                'value' => $product_sku,
                'compare' => '='
            )
        )
    ));

Leave a Reply

Your email address will not be published.