If you are looking into this post, it means you have setup the woocommerce/wordpress where you approve the users manually. This helps you in handling the delivery if customer is from the place where you don’t deliver the products.
The notification email to the site admin makes sure that customer is not changing the shipping address at check out time. Even a smallest change in shipping address will notify the admin and admin can set the user status pending to restrict him by placing an order.
The below piece of code has to be placed in functions.php. Make sure you have child theme active because theme update may override this code.
// Send notification email when customer changes address.
add_action( ‘woocommerce_customer_save_address’,’notify_admin_customer_address_change’, 10, 2);
function notify_admin_customer_address_change( $user_id ) {
// Set the $from_name, $from_email, and $to for your site.
$from_name = ‘WebSite NAme’;
$from_email = ‘threepupilsdesk@gmail.com’;
$to = ‘adminemailid@threepupils.com’;
global $woocommerce, $current_user;
// format email
$message = ‘Username: ‘ . $current_user->user_login . “\n”;
$message .= ‘User Email: ‘ . $current_user->user_email . “\n”;
$message .= ‘User First Name: ‘ . $current_user->user_firstname . “\n”;
$message .= ‘User Last Name: ‘ . $current_user->user_lastname . “\n”;
$message .= “\n”;
$message .= “\n”;
$message .= “Billing Address:\n”;
// get the data from the profile after it’s set by the customer save
$woocommerce->customer->set_default_data();
$message .= $woocommerce->customer->get_address() . “\n”;
$address_2 = $woocommerce->customer->get_address_2();
if ($address_2 != ”) {
$message.= $address_2 . “\n”;
}
$message .= $woocommerce->customer->get_city() . ” “;
$message .= $woocommerce->customer->get_state() . ” “;
$message .= $woocommerce->customer->get_postcode() . “\n”;
$message .= $woocommerce->customer->get_country() . “\n\n”;
$message .= “Shipping Address:\n”;
$message .= $woocommerce->customer->get_shipping_address() . “\n”;
$shipping_address_2 = $woocommerce->customer->get_shipping_address_2();
if ($shipping_address_2 != ”) {
$message .= $shipping_address_2 . “\n”;
}
$message .= $woocommerce->customer->get_shipping_city() . ” “;
$message .= $woocommerce->customer->get_shipping_state() . ” “;
$message .= $woocommerce->customer->get_shipping_postcode() . “\n”;
$message .= $woocommerce->customer->get_shipping_country();
$headers = ‘From: ‘ . $from_name . ‘ <‘ . $from_email . ‘>’ . “\r\n”;
wp_mail($to, ‘Customer Address Change Notice’, $message, $headers);
}
Let us know your comments.
#WooCommerce #Wordpress #ShippingAddress #eMailNotification #Functions.php
Recent Comments