wp = $wp; $this->helper = $helper; } function getCustomerOrderCount($customer_email) { // registered user $user = $this->wp->getUserBy('email', $customer_email); if ($user) { return $this->helper->wcGetCustomerOrderCount($user->ID); } // guest user return $this->getGuestCustomerOrderCountByEmail($customer_email); } private function getGuestCustomerOrderCountByEmail($customer_email) { global $wpdb; $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts as posts LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id WHERE meta.meta_key = '_billing_email' AND posts.post_type = 'shop_order' AND meta_value = '" . $this->wp->escSql($customer_email) . "' " ); return (int)$count; } }