WP e-Commerce and the “Alabama Problem” in Store Receipts
Posted: October 18th, 2012
Author: Ben Heller
If you’ve been reading our blog over the last couple months, you might be aware that we have some experience “improving” (read: “fixing bugs in”) the WP e-Commerce (WPEC) platform. Lately we’ve received a number of inquiries from our clients as to why so many sales receipts read “Alabama” as the state. Could it be that customers are just lazy and are leaving the state dropdown at its default, or is there some deeper issue here? It turns out that WPEC is actually saving the correct data, but for international orders it’s displaying “Alabama” instead of the actual state or region. Very sloppy, WPEC! Let’s take a look at /wp-content/plugins/wp-e-commerce/wpsc-includes/purchaselogs.class.php. On version 22.214.171.124 it’s on line 457, at the start of the wpsc_display_purchlog_buyers_address() function. By default this function reads:
if(is_numeric($purchlogitem->extrainfo->billing_region)) $state = wpsc_get_region($purchlogitem->extrainfo->billing_region); else $state = $purchlogitem->userinfo['billingstate']['value'];
It’s this top part that’s pulling the data using wpsc_get_region from the $purchlogitem object. We want to do this only for US orders, and throw all international orders to the ELSE statement. We’ll fix it by narrowing the parameters of their IF statement. Our revised function now reads:
if(is_numeric($purchlogitem->extrainfo->billing_region) && (($purchlogitem->extrainfo->billing_country == 'US'))) $state = wpsc_get_region($purchlogitem->extrainfo->billing_region); else $state = $purchlogitem->userinfo['billingstate']['value'];
We now require the billing country to be ‘US’, or the ELSE statement is triggered to pull the state from WPEC’s userinfo object. We’ll be following this up with a post on how to implement this fix as a standalone upgrade (without editing the WPEC core files), but we wanted to share the code so folks can fix this up right now. Remember to leave the global $purchlogitem and return statement at the top and bottom of the function.