Forked from BFTrick/woocommerce-email-new-address.php
Last active
May 18, 2018 13:09
-
-
Save alexv66/569b618e4613f0ff050a3b5cb27c7110 to your computer and use it in GitHub Desktop.
Email the site admin when a customer changes their address, adapted for Woocommerce 3.3.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: WooCommerce Email Customer Address | |
* Plugin URI: https://gist.github.com/BFTrick/7891074 | |
* Description: Email the site admin when a customer changes their address | |
* Author: Patrick Rauland | |
* Author URI: http://patrickrauland.com/ | |
* Version: 1.0.1 | |
* | |
* This program is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation, either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License | |
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |
* | |
* @author Patrick Rauland | |
* @since 1.0 | |
*/ | |
add_action( 'woocommerce_customer_save_address', 'patricks_email_customer_address', 20, 2 ); | |
function patricks_email_customer_address( $user_id , $type_address ) { | |
global $current_user; | |
// get user data | |
$current_user = wp_get_current_user(); | |
// get shipping data | |
$address = patricks_get_formatted_address( $type_address ); | |
// get admin email | |
$email = get_option( 'admin_email', '' ); | |
$subject = "Adressänderung Abonnent - EXPLORER"; | |
// 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 .= "New $type_address address: \n" . $address . "\n"; | |
// make sure we have all of the required data | |
if ( empty ( $email ) ) { | |
return; | |
} | |
//die("<pre>".$message); | |
// send email | |
wp_mail( $email, $subject, $message ); | |
} | |
function patricks_get_formatted_address( $type_address ) { | |
// get the data from the profile after it's set by the customer save | |
if( $type_address =="shipping" ) | |
{ | |
$address = ""; | |
$address .= WC()->customer->get_shipping_address(); | |
$address .= "\n"; | |
$address .= WC()->customer->get_shipping_address_2(); | |
$address .= "\n"; | |
$address .= WC()->customer->get_shipping_city(); | |
$address .= " "; | |
$address .= WC()->customer->get_shipping_state(); | |
$address .= ", "; | |
$address .= WC()->customer->get_shipping_postcode(); | |
$address .= "\n"; | |
$address .= WC()->customer->get_shipping_country(); | |
} else { | |
$address = ""; | |
$address .= WC()->customer->get_billing_address(); | |
$address .= "\n"; | |
$address .= WC()->customer->get_billing_address_2(); | |
$address .= "\n"; | |
$address .= WC()->customer->get_billing_city(); | |
$address .= " "; | |
$address .= WC()->customer->get_billing_state(); | |
$address .= ", "; | |
$address .= WC()->customer->get_billing_postcode(); | |
$address .= "\n"; | |
$address .= WC()->customer->get_billing_country(); | |
} | |
return $address; | |
} | |
// That's all folks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment