Мне удалось немного расширить код, указанный выше ...
// Make Billing Address not required
add_filter( 'woocommerce_default_address_fields' , 'filter_default_address_fields', 20, 1 );
function filter_default_address_fields( $address_fields ) {
// Only on checkout page
if( ! is_checkout() ) return $address_fields;
// All field keys in this array
$key_fields = array('country','company','address_1','address_2','city','state','postcode');
// Loop through each address fields (billing and shipping)
foreach( $key_fields as $key_field )
$address_fields[$key_field]['required'] = false;
return $address_fields;
}
Скрыть адрес для выставления счета, если наложенный платеж, или показать, если кредитная карта
jQuery(function(){
jQuery( 'body' )
.on( 'updated_checkout', function() {
usingGateway();
jQuery('input[name="payment_method"]').change(function(){
console.log("payment method changed");
usingGateway();
});
});
});
function usingGateway(){
console.log(jQuery("input[name='payment_method']:checked").val());
if(jQuery('form[name="checkout"] input[name="payment_method"]:checked').val() == 'cod'){
jQuery('.woocommerce-billing-fields #billing_company_field, .woocommerce-billing-fields #billing_country_field, .woocommerce-billing-fields #billing_address_1_field, .woocommerce-billing-fields #billing_address_2_field, .woocommerce-billing-fields #billing_city_field, .woocommerce-billing-fields #billing_state_field, .woocommerce-billing-fields #billing_postcode_field, .woocommerce-shipping-fields').hide();
//Etc etc
} else {
jQuery('.woocommerce-billing-fields #billing_company_field, .woocommerce-billing-fields #billing_country_field, .woocommerce-billing-fields #billing_address_1_field, .woocommerce-billing-fields #billing_address_2_field, .woocommerce-billing-fields #billing_city_field, .woocommerce-billing-fields #billing_state_field, .woocommerce-billing-fields #billing_postcode_field, .woocommerce-shipping-fields').show();
}
}