Get all WooCommerce products and variations with PHP

$products = wc_get_products( array( 
    'limit'   => -1, 
    'return'  => 'ids', 
    'orderby' => 'ID', 
    'order'   => 'ASC', 
    'type'    => array_merge( array_keys( wc_get_product_types() ), array( 'variation' ) ),
) );

foreach ( $products as $product_id ) {
    // do stuff here...
}

No comments yet.

Leave a Reply