I am utilizing the next code the take away checkout fields when the Native pickup delivery methodology is chosen.
The code work as espected for the native woocommerce billing fields but it surely would not take away the ‘required’ validation for the customized fields created from the WooCommerce Checkout Area Editor plugin.
It hides the customized fields however they keep required and the shape cannot submit.
After I choose the Native pickup delivery methodology it removes the customized fields ‘billing_region’ and ‘billing_cityalt’ however once I press the checkout button it present an validation error that the fields are empty and should be crammed.
The query is how the make the customized fields not required?
I attempted the [‘required’] = false; and ‘unset’ however this strategy would not work for customized fields.
add_filter( 'woocommerce_checkout_fields', 'hide_local_pickup_method' );
operate hide_local_pickup_method( $fields_pickup ) {
// change under for the tactic
$shipping_method_pickup ='local_pickup:8';
// change under for the record of fields. Add (or delete) the sphere title you need (or don’t need) to make use of
$hide_fields_pickup = array( 'billing_address_1', 'billing_address_2','billing_region', 'billing_cityalt');
$chosen_methods_pickup = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping_pickup = $chosen_methods_pickup[0];
foreach($hide_fields_pickup as $field_pickup ) {
if ($chosen_shipping_pickup == $shipping_method_pickup) {
$fields_pickup['billing'][$field_pickup]['required'] = false;
$fields_pickup['billing'][$field_pickup]['class'][] = 'hide_pickup';
}
$fields_pickup['billing'][$field_pickup]['class'][] = 'billing-dynamic_pickup';
}
return $fields_pickup;
}
// Native Pickup - conceal fields
add_action( 'wp_head', 'local_pickup_fields', 999 );
operate local_pickup_fields() {
if (is_checkout()) :
?>
<model>
.hide_pickup {show: none!vital;}
</model>
<script>
jQuery( operate( $ ) {
if ( typeof woocommerce_params === 'undefined' ) {
return false;
}
$(doc).on( 'change', '#shipping_method enter[type="radio"]', operate() {
// change local_pickup:4 accordingly
$('.billing-dynamic_pickup').toggleClass('hide_pickup', this.worth == 'local_pickup:8');
});
});
</script>
<?php
endif;
}