Skip to content

Instantly share code, notes, and snippets.

@webaware
Last active December 13, 2015 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webaware/4964078 to your computer and use it in GitHub Desktop.
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/
<?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();
@ablears
Copy link

ablears commented Feb 12, 2014

Excellent work, thanks for sharing. Shame you've moved on to Woo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment