How can i get WooCommerce list users without a purchase

$all_users = get_users();

if ( !empty( $all_users ) ) {
	$no_order_user_list = [];
	foreach($all_users as $user) {
		if ( in_array( 'administrator', $user->roles ) )
			continue;
		$customer_orders = get_posts(array(
			 'numberposts' => -1,
			 'meta_key'    => '_customer_user',
			 'meta_value'  => $user->ID,
			 'post_type'   => wc_get_order_types(),
			 'post_status' => array('wc-pending', 'wc-processing', 'wc-completed') //array_keys(wc_get_order_statuses()),
		));

		if( count( $customer_orders ) == 0 ) {
			$no_order_user_list [] = $user;
		}
	}
}

echo '<pre>';
print_r($no_order_user_list);
echo '</pre>';

Leave a Reply

Your email address will not be published. Required fields are marked *