musa baltaci
musa baltaci

Reputation: 139

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 '';
    }

Upvotes: 1

Views: 140

Answers (1)

LoicTheAztec
LoicTheAztec

Reputation: 254362

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;
}

Upvotes: 1

Related Questions