0

I am using WooCommerce and have the 'Ship to a Different Address' section enabled on the Checkout page. I would like to keep it there, but I am trying to remove a couple fields. More specifically I am trying to remove first name, last name & the state/province fields. I added the following code to my child theme's functions.php file:

function custom_override_checkout_fields( $fields ) {
    unset($fields['billing']['billing_first_name']);
    unset($fields['billing']['billing_last_name']);
    unset($fields['billing']['billing_state']);
    unset($fields[‘shipping’][‘shipping_first_name’]);
    unset($fields[‘shipping’][‘shipping_last_name’]);
    unset($fields[‘shipping’][‘shipping_state’]);
    return $fields;
}

The billing fields are eliminated when I use this code, but all shipping fields remain when I open up 'Ship to a different address'. Not exactly sure what I am doing incorrect here, any help would be appreciated. Thanks for your time.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Z.Horsman
  • 3
  • 3

1 Answers1

0

please check, there is syntax error in the code below. because i think WordPress not accept these quotes in array.

unset($fields[‘shipping’][‘shipping_first_name’]);
unset($fields[‘shipping’][‘shipping_last_name’]);
unset($fields[‘shipping’][‘shipping_state’]);

Please use single quotes, please use the code below and then test

unset($fields['shipping']['shipping_first_name']);
unset($fields['shipping']['shipping_last_name']);
unset($fields['shipping']['shipping_state']);
Yogesh Garg
  • 299
  • 3
  • 10