Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Woocommerce never save shipping address on checkout page

By default Woocommerce saves the billing and shipping address on the checkout page.

I am searching for a way to prevent Woocommerce from saving the values in the shipping address. So all the fields in the shipping address should be empty.

In another thread I found a partial solution. It works great, but it also makes the billing address empty:

add_filter('woocommerce_checkout_get_value','__return_empty_string',10);

Is there a way to do this only for shipping address?

Big thx!

like image 750
Lefteris Avatar asked Nov 15 '25 17:11

Lefteris


1 Answers

You could change the code like this...

add_filter( 'woocommerce_checkout_get_value', 'reigel_empty_checkout_shipping_fields', 10, 2 );
function reigel_empty_checkout_shipping_fields( $value, $input ) {
    /*
    Method 1
    you can check the field if it has 'shipping_' on it...
    if ( strpos( $input, 'shipping_' ) !== FALSE ) {
        $value = '';
    }

    Method 2
    put all the fields you want in an array...
    */
    $shipping_fields = array(
        //'shipping_first_name',
        //'shipping_last_name',
        'shipping_company',
        'shipping_country',
        'shipping_address_1',
        'shipping_address_2',
        'shipping_city',
        'shipping_state',
        'shipping_country',
        'shipping_postcode'
    );

    if ( in_array( $input, $shipping_fields ) ) {
        $value = '';
    }

    return $value;
}
like image 193
Reigel Avatar answered Nov 18 '25 08:11

Reigel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!