簡體   English   中英

WooCommerce:無需購買即可列出用戶

[英]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>';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM