Last active
December 13, 2015 19:38
-
-
Save webaware/4964078 to your computer and use it in GitHub Desktop.
Extend WP e-Commerce customer emails to add shipping and billing details. Just drop this into a plugin, or add to your theme's functions.php. Some discussion over at my blog post about extending notification emails in wp-e-commerce -- http://snippets.webaware.com.au/snippets/extend-notification-emails-in-wp-e-commerce/
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 | |
/** | |
* extend WP e-Commerce customer emails to add shipping and billing details | |
* drop this into a plugin, or add to your theme's functions.php | |
*/ | |
class WpscExtendCustEmail { | |
/** | |
* add filter hooks | |
*/ | |
public function __construct() { | |
add_filter('wpsc_purchase_log_customer_notification_raw_message', array($this, 'customerMessage'), 10, 2); | |
} | |
/** | |
* intercept filter hook for customer notification message | |
* @param string $msg the customer notification message | |
* @param WPSC_Purchase_Log_Customer_Notification $log_notification | |
* @return string | |
*/ | |
public function customerMessage($msg, $log_notification) { | |
$purchase_log = $log_notification->get_purchase_log(); | |
$form_data = new WPSC_Checkout_Form_Data($purchase_log->get('id')); | |
$cust_info = $form_data->get_gateway_data(); | |
foreach ($cust_info as $heading => $section) { | |
// remove underscores from heading, convert to uppercase, add to message | |
$heading = strtoupper(strtr($heading, '_', ' ')); | |
$msg .= "\n\n$heading\n" . str_repeat('=', strlen($heading)) . "\n"; | |
// iterate over customer fields | |
foreach ($section as $label => $value) { | |
if ($value) { | |
// if value is a country code, convert it to a country name | |
if ($label == 'country') { | |
$value = wpsc_get_country($value); | |
} | |
// remove underscores from label, convert first character to uppercase | |
$label = ucfirst(strtr($label, '_', ' ')); | |
$msg .= "$label: $value\n"; | |
} | |
} | |
} | |
return $msg; | |
} | |
} | |
new WpscExtendCustEmail(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Excellent work, thanks for sharing. Shame you've moved on to Woo!