Last active
February 26, 2018 14:17
-
-
Save Yame-/d154d574ee7df2f5b3eb to your computer and use it in GitHub Desktop.
Retrieving billing_first_name, billing_last_name, ... via Sessions - WooCommerce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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