我正在为Woocommerce开发一个运输插件,我正在尝试从结帐页面获取结算名字字段的价值。从我迄今为止尝试过的,我想我应该让Ajax刷新一脚在编辑每个字段之后,不仅仅是关于地址的字段。
我把它放在我的functions.php中:
add_action('woocommerce_checkout_update_order_review', 'get_customer_details');
function get_customer_details($post_data){
global $woocommerce;
global $order;
// 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];
}
// Populate the session
foreach($details as $key){
if(isset($post[$key]))
$woocommerce->session->set($key, $post[$key]);
}
}
在我的JS文件中,我有这个:
jQuery(document).ready(function () {
jQuery( 'form.checkout' ).on( 'input change', '#billing_first_name, #billing_last_name', function() {
jQuery( 'body' ).trigger( 'init_checkout' );
});
});
现在我可以通过以下方式访问Billing first name的值:
$woocommerce->session->get('billing_first_name');
并在编辑Billing名字后启动ajax刷新;问题是它不会更新Billing名字的值,我需要它来做。
有什么想法吗? 谢谢!