Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Plugin Name: Email Checker
- * Description: Checks the billing email address on order created and displays status in the admin order page.
- * Version: 1.0
- * Author: Your Name
- */
- // Check Email Existence
- function check_email_existence($email) {
- list($user, $domain) = explode('@', $email);
- $host = gethostbyname($domain);
- $port = 25;
- $timeout = 10;
- $socket = fsockopen($host, $port, $errno, $errstr, $timeout);
- if (!$socket) {
- return false;
- }
- $response = fread($socket, 1024);
- if (!preg_match('/^220/', $response)) return false;
- // EHLO request
- fwrite($socket, "EHLO $host\r\n");
- $response = fread($socket, 1024);
- if (!preg_match('/^250/', $response)) return false;
- // MAIL FROM request
- fwrite($socket, "MAIL FROM: <check@$host>\r\n");
- $response = fread($socket, 1024);
- if (!preg_match('/^250/', $response)) return false;
- // RCPT TO request
- fwrite($socket, "RCPT TO: <$email>\r\n");
- $response = fread($socket, 1024);
- if (!preg_match('/^250/', $response)) return false;
- // QUIT request
- fwrite($socket, "QUIT\r\n");
- fclose($socket);
- return true;
- }
- // Verify email on order creation and update post meta
- add_action('woocommerce_new_order', 'verify_email_on_order_created');
- function verify_email_on_order_created($order_id) {
- $order = wc_get_order($order_id);
- $email = $order->get_billing_email();
- $email_exists = check_email_existence($email);
- if (!$email_exists) {
- update_post_meta($order_id, '_billing_email_invalid', 'yes');
- } else {
- update_post_meta($order_id, '_billing_email_valid', 'yes');
- }
- }
- // Add meta box to display email verification status in the admin order edit page
- add_action('add_meta_boxes', 'add_email_checker_meta_box');
- function add_email_checker_meta_box() {
- add_meta_box('email-checker-meta-box', 'Email Verification', 'email_checker_meta_box_content', 'shop_order', 'side', 'high');
- }
- function email_checker_meta_box_content($post) {
- $email_valid = get_post_meta($post->ID, '_billing_email_valid', true);
- $email_invalid = get_post_meta($post->ID, '_billing_email_invalid', true);
- if ($email_valid) {
- echo "Email is valid.";
- } elseif ($email_invalid) {
- echo "Email is invalid.";
- } else {
- echo "Email hasn't been checked yet.";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement