【发布时间】:2019-01-23 13:54:29
【问题描述】:
我们可以在处理付款之前使用 jquery 在 woocommerce 中获取帐单地址信息吗?使用最后一个焦点元素,我们可以获得输入的账单地址名字,姓氏等。
【问题讨论】:
标签: php jquery wordpress woocommerce
我们可以在处理付款之前使用 jquery 在 woocommerce 中获取帐单地址信息吗?使用最后一个焦点元素,我们可以获得输入的账单地址名字,姓氏等。
【问题讨论】:
标签: php jquery wordpress woocommerce
这是一个在 jQuery 中获取客户账单信息的示例(在处理付款之前):
add_action( 'wp_footer', 'custom_checkout_js_script' );
function custom_checkout_js_script() {
// Targeting cart and checkout pages
if ( is_cart() || ( is_checkout() && ! is_wc_endpoint_url() ) ) :
$billing_first_name = WC()->customer->get_billing_first_name();
$billing_last_name = WC()->customer->get_billing_last_name();
$billing_address_1 = WC()->customer->get_billing_address_1();
$billing_address_2 = WC()->customer->get_billing_address_2();
$billing_postcode = WC()->customer->get_billing_postcode();
$billing_city = WC()->customer->get_billing_city();
$billing_state = WC()->customer->get_billing_state();
$billing_country = WC()->customer->get_billing_country();
?>
<script type="text/javascript">
jQuery( function($){
var billing_first_name = '<?php echo $billing_first_name; ?>',
billing_last_name = '<?php echo $billing_last_name; ?>',
billing_address_1 = '<?php echo $billing_address_1; ?>',
billing_address_2 = '<?php echo $billing_address_2; ?>',
billing_postcode = '<?php echo $billing_postcode; ?>',
billing_city = '<?php echo $billing_city; ?>',
billing_state = '<?php echo $billing_state; ?>',
billing_country = '<?php echo $billing_country; ?>';
});
</script>
<?php
endif;
}
代码进入您的活动子主题(或活动主题)的 function.php 文件中。经过测试并且可以工作。
【讨论】: