简体   繁体   中英

Clear shipping_*fields in WooCommerce Checkout

Trying to always have the "Ship to a different adress" cleared when a user is buying in WooCommerce Checkout. The following code is though doing aboslutely nothing. Does it have todo with cookies?

    add_filter( 'woocommerce_checkout_get_value', 'remove_clear_checkout_shipping_fields', 10, 2 );
function remove_clear_checkout_shipping_fields( $value, $input ) {
    if ( strpos( $input, 'shipping_' ) !== FALSE ) {
        $value = '';
    }
}

This way you can modify each field:

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

function custom_override_checkout_fields( $fields ) {

  $fields['shipping']['shipping_first_name'] = '';
  $fields['shipping']['shipping_last_name'] = '';
  $fields['shipping']['shipping_company'] = '';
  $fields['shipping']['shipping_address_1'] = '';
  $fields['shipping']['shipping_address_2'] = '';
  $fields['shipping']['shipping_city'] = '';
  $fields['shipping']['shipping_postcode'] = '';
  $fields['shipping']['shipping_country'] = '';
  $fields['shipping']['shipping_state'] = '';

  return $fields;
}

Just remove unnecessary fields.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM