Skip to content

Instantly share code, notes, and snippets.

@Yame-
Last active February 26, 2018 14:17
Show Gist options
  • Save Yame-/d154d574ee7df2f5b3eb to your computer and use it in GitHub Desktop.
Save Yame-/d154d574ee7df2f5b3eb to your computer and use it in GitHub Desktop.
Retrieving billing_first_name, billing_last_name, ... via Sessions - WooCommerce
<?php
/*
Add this code to your functions.php
*/
add_action('woocommerce_checkout_update_order_review', 'get_customer_details');
function get_customer_details($post_data){
global $woocommerce;
// Details you want injected into WooCommerce session.
$details = array('billing_first_name', 'billing_last_name', 'billing_company', 'billing_email', 'billing_phone');
// Parsing data
$post = array();
$vars = explode('&', $post_data);
foreach ($vars as $k => $value){
$v = explode('=', urldecode($value));
$post[$v[0]] = $v[1];
}
// Population session
foreach($details as $key){
if(isset($post[$key]))
$woocommerce->session->set($key, $post[$key]);
}
/*
Now you can just $woocommerce->session->get('billing_first_name');
*/
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment