I want to clean up the user database and remove accounts that haven't made a purchase. So far I only found solutions to list users that purchased an item. How to do the opposite?
Here is the users with no orders:
$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>';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.