一旦我在结帐页面上更改了发运选项,我想显示/隐藏某些字段,但是一旦我手动重新加载页面后它就起作用了,那么我添加了一个jQuery代码来重新加载页面-
jQuery('form.checkout').on('change','input[name^="shipping_method"]',function() {
完整代码-
<?php
// Add custom Theme Functions here
add_filter('woocommerce_checkout_fields', 'xa_remove_billing_checkout_fields');
function xa_remove_billing_checkout_fields($fields) {
$first_shipping_method ='free_shipping:1'; // Set the desired shipping method to hide the checkout field(s).
$second_shipping_method ='free_shipping:2'; // Set the desired shipping method to hide the checkout field(s).
$third_shipping_method ='local_pickup:3'; // Set the desired shipping method to hide the checkout field(s).
global $woocommerce;
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];
if ($chosen_shipping == $first_shipping_method || $chosen_shipping == $third_shipping_method) {
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);
}
if ($chosen_shipping == $second_shipping_method || $chosen_shipping == $third_shipping_method) {
unset($fields['billing']['billing_pick_up']);
}
?>
<script type="text/javascript">
jQuery('form.checkout').on('change','input[name^="shipping_method"]',function() {
var val = jQuery( this ).val();
if (val) {
location.reload();
}
});
</script>
<?php
return $fields;
}
但是它对我不起作用,你能指导我吗?
与我有同样的问题。更改特定的送货方式后,Woocommerce结帐页面会重新加载,请选择