Aleksandar-Mitic
2/26/2018 - 2:17 PM

Retrieving billing_first_name, billing_last_name, ... via Sessions - WooCommerce

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');
	*/
}
?>