If you need variation IDs for a WooCommerce product and you know the WC product ID, you can use one of the two following code snippets to get an array of the possible variation IDs.
Get all product variation IDs regardless of visibility
$product = wc_get_product( $product_id ); $variation_ids = $product->get_children();
Get available (visible) production variation IDs
$product = wc_get_product( $product_id ); $variations = $product->get_available_variations(); $variation_ids = wp_list_pluck( $variations, 'variation_id' );
Leave a Reply