Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

All Orders

// WP_Query arguments
$args = array(
	'post_type'              => array( 'shop_order' ),
	'post_status'            => array( 'wc-completed' ),
	'posts_per_page'         => '-1',
	'date_query'             => array(
		'relation' => 'AND',
		array(
			'before' => array(
				'year'  => 2022,
				'month' => 4,
				'day'   => 15,
			),
			'after' => array(
				'year'  => 2022,
				'month' => 1,
				'day'   => 1,
			),
			'inclusive' => true,
		),
	),
	'meta_query'             => array(
		'relation' => 'AND',
		array(
			'key'     => '_product_id',
			'value'   => '$_product_id',
			'compare' => '=',
		),
	),
);

// The Query
$order_ids = new WP_Query( $args );