Как только я изменяю опцию доставки на странице оформления заказа, я хочу показать / скрыть некоторые поля, но это сработало, как только я перезагрузил страницу вручную, затем я добавил код 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;
}
Но это не работает для меня, можете ли вы вести меня?