Clear checkout fields for specific user(s) in WooCommerce

This code clear all input of the checkout page for everyone. i want to clear all input for specific user. How can i do this.

 add_filter( 'woocommerce_checkout_get_value' , 'clear_checkout_fields' );
function clear_checkout_fields($input)
    {
        return '';
    }

Answer

For a defined user ID you can use (set the related user Id in IF statement):

add_filter( 'woocommerce_checkout_get_value', 'clear_checkout_fields' );
function clear_checkout_fields( $input ) {
    if ( get_current_user_id() == 259 ) {
        return '';
    }
    return $input;
}

Or for an array of user ids:

add_filter( 'woocommerce_checkout_get_value', 'clear_checkout_fields' );
function clear_checkout_fields( $input ) {
    if ( in_array( get_current_user_id(), array( 259, 321, 336 ) ) {
        return '';
    }
    return $input;
}

Leave a Reply

Your email address will not be published. Required fields are marked *