简体   繁体   English

WooCommerce:无需购买即可列出用户

[英]WooCommerce: list users without a purchase

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>';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM