• Resolved spanky22

    (@spanky22)


    Hello Woo People,

    I will often have customers who ship to many different locations.
    When they checkout, their data is pre-filled in on the checkout form.

    I am using this code now: (in my child functions theme)
    add_filter('woocommerce_checkout_get_value','__return_empty_string',10);
    This clears everything! Even the States drop down selection from being a dropdown.

    Is there anything else I could do differently to keep the pre-filled data on the billing side, but clear the shipping side of the form?

    Thanks in advance,
    – Spank

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,
    Would this post help?
    https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/

    According to this, you could use the filter woocommerce_shipping_fields instead of woocommerce_checkout_get_value.

    If that doesn’t work, this user on stackoverflow seems to have had a similar problem and a working solution.

    Hope one of these help.

    Thread Starter spanky22

    (@spanky22)

    Thanks Menaka,
    Stackoverflow’s solution kept giving me the catastrophic blank white screen.
    The woo help page is just info to edit the field text, not really clear it.
    Then again, i might just be overlooking an answer.

    If this code clears all fields, how could I possibly change it to clear just the ship to?
    add_filter('woocommerce_checkout_get_value','__return_empty_string',10);

    I tried:
    add_filter('woocommerce_shipping_fields','__return_empty_string',10);
    but this didn’t clear anything.
    Am I missing something?

    Thanks for helping!

    Hi @spanky22,
    I tried both the solutions on my local installation. The woocommerce_shipping_fields solution did not really help.

    But the stackoverflow solution worked perfectly. Can you check it again?
    The white screen might be due to some missed/extra characters while doing copy+paste?

    Thread Starter spanky22

    (@spanky22)

    Hi @menakas

    (Resolved)
    Thanks for your input. I double checked the code and it worked this time!
    Thanks so much for helping.

    For reference, this is what I used:

    /*** Remove or clear shipping fields ***/
    
    add_filter( 'woocommerce_checkout_get_value', 'reigel_empty_checkout_shipping_fields', 10, 2 );
    function reigel_empty_checkout_shipping_fields( $value, $input ) {
        /*
        Method 2
        put all the fields you want in an array...
        */
        $shipping_fields = array(
            'shipping_first_name',
            'shipping_last_name',
            'shipping_phone',
            'shipping_company',
            'shipping_country',
            'shipping_address_1',
            'shipping_address_2',
            'shipping_city',
            'shipping_country',
            'shipping_postcode'
        );
    
        if ( in_array( $input, $shipping_fields ) ) {
            $value = '';
        }
    
        return $value;
    }
    /*****/
    • This reply was modified 8 years, 2 months ago by spanky22.
    • This reply was modified 8 years, 2 months ago by spanky22.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Keep Billing Fields but how to clear Ship To fields’ is closed to new replies.