Create a gist now

Instantly share code, notes, and snippets.

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

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