Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jessepearson/2dac577e5298cc78dbbfa1e9b920601c to your computer and use it in GitHub Desktop.

Select an option

Save jessepearson/2dac577e5298cc78dbbfa1e9b920601c to your computer and use it in GitHub Desktop.

Revisions

  1. jessepearson revised this gist Jun 17, 2016. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions woocommerce-email-new-address.php
    Original file line number Diff line number Diff line change
    @@ -61,6 +61,9 @@ function patricks_email_customer_address( $user_id ) {
    function patricks_get_formatted_shipping_address() {
    global $woocommerce;

    // get the data from the profile after it's set by the customer save
    $woocommerce->customer->set_default_data();

    $address = '';

    $address .= $woocommerce->customer->get_shipping_address();
  2. @BFTrick BFTrick revised this gist Dec 10, 2013. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions woocommerce-email-new-address.php
    Original file line number Diff line number Diff line change
    @@ -43,8 +43,6 @@ function patricks_email_customer_address( $user_id ) {
    $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 .= 'User display name: ' . $current_user->display_name . "\n";
    $message .= 'User ID: ' . $current_user->ID . "\n";
    $message .= "\n";
    $message .= "\n";
    $message .= 'New shipping address: ' . $shipping_address . "\n";
  3. @BFTrick BFTrick revised this gist Dec 10, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion woocommerce-email-new-address.php
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    <?php
    /**
    * Plugin Name: WooCommerce Email Customer Address
    * Plugin URI: https://gist.github.com/BFTrick/_______
    * 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/
  4. @BFTrick BFTrick created this gist Dec 10, 2013.
    84 changes: 84 additions & 0 deletions woocommerce-email-new-address.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,84 @@
    <?php
    /**
    * Plugin Name: WooCommerce Email Customer Address
    * Plugin URI: https://gist.github.com/BFTrick/_______
    * Description: Email the site admin when a customer changes their address
    * Author: Patrick Rauland
    * Author URI: http://patrickrauland.com/
    * Version: 1.0
    *
    * 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
    */

    function patricks_email_customer_address( $user_id ) {

    global $current_user;

    // get user data
    get_currentuserinfo();

    // get shipping data
    $shipping_address = patricks_get_formatted_shipping_address();

    // get admin email
    $email = get_option( 'admin_email', '' );
    $subject = "Customer Changed Address";

    // 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 .= 'User display name: ' . $current_user->display_name . "\n";
    $message .= 'User ID: ' . $current_user->ID . "\n";
    $message .= "\n";
    $message .= "\n";
    $message .= 'New shipping address: ' . $shipping_address . "\n";

    // make sure we have all of the required data
    if ( empty ( $email ) ) {
    return;
    }

    // send email
    wp_mail( $email, $subject, $message );

    }
    add_action( 'woocommerce_customer_save_address', 'patricks_email_customer_address', 20 );

    function patricks_get_formatted_shipping_address() {
    global $woocommerce;

    $address = '';

    $address .= $woocommerce->customer->get_shipping_address();
    $address .= "\n";
    $address .= $woocommerce->customer->get_shipping_address_2();
    $address .= "\n";
    $address .= $woocommerce->customer->get_shipping_city();
    $address .= " ";
    $address .= $woocommerce->customer->get_shipping_state();
    $address .= ", ";
    $address .= $woocommerce->customer->get_shipping_postcode();
    $address .= "\n";
    $address .= $woocommerce->customer->get_shipping_country();

    return $address;
    }


    // That's all folks!