WP-Eccommerce Get Purchase Log Data

To retrieve the purchase log data to extract customer email for example use this within the function:

global $wpdb;

//This grabs the purchase log id from the database that refers to the $sessionid

$purchase_log = $wpdb->get_row(
"SELECT * FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `sessionid`= ".$sessionid." LIMIT 1" ,ARRAY_A) ;
//This grabs the users info using the $purchase_log from the previous SQL query
  $usersql = "SELECT `".WPSC_TABLE_SUBMITED_FORM_DATA."`.value,
`".WPSC_TABLE_CHECKOUT_FORMS."`.`name`,
`".WPSC_TABLE_CHECKOUT_FORMS."`.`unique_name` FROM
`".WPSC_TABLE_CHECKOUT_FORMS."` LEFT JOIN
`".WPSC_TABLE_SUBMITED_FORM_DATA."` ON
`".WPSC_TABLE_CHECKOUT_FORMS."`.id =
`".WPSC_TABLE_SUBMITED_FORM_DATA."`.`form_id` WHERE
`".WPSC_TABLE_SUBMITED_FORM_DATA."`.`log_id`=".$purchase_log['id']."";

$userinfo = $wpdb->get_results($usersql, ARRAY_A);

//get for example, customer email address
foreach((array)$userinfo as $key => $value){

if(($value['unique_name']=='billingemail') && $value['value'] != ''){
$customer_email = $value['value'];
}
}

Keys correspond to the checkout fields unique names

Leave a Comment