Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
740 B
0
Indexable
Never
<?php
add_filter( 'woocommerce_checkout_fields', function ( array $fields ) {

if ( ! is_ajax() ) {
return $fields;
}

$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping_methods = $chosen_shipping_methods[0] ?? '';

if ( str_contains( $chosen_shipping_methods, 'local_pickup' ) ) {

$fields['billing']['billing_address_1']['required'] = false;
$fields['billing']['billing_address_2']['required'] = false;
$fields['billing']['billing_postcode']['required'] = false;

$fields['shipping']['shipping_address_1']['required'] = false;
$fields['shipping']['shipping_address_2']['required'] = false;
$fields['shipping']['shipping_postcode']['required'] = false;
}

return $fields;
});
Leave a Comment