• Resolved rawald

    (@rawald)


    Hey there,

    Currently busy creating a delivery store. Now the process is the following: User registers, page sends them to My Account -> Billing Address and fills this in. Now our gripe is due to a rewards system and limited delivery areas we only want them to use the address from My Account as it is checked against a POS that is linked but of course they need to be able to go to the check out page, here we only want the same details from the billing address (removed shipping since it’s one and the same for us). How do we not allow the user to be able to change the address on the Check Out page (it autofills right now from the account page address they entered).

Viewing 3 replies - 1 through 3 (of 3 total)
  • Mirko P.

    (@rainfallnixfig)

    Hi @rawald,

    Based on this Stack Overflow thread you can use the following snippet and make the billing_address_1 and billing_address_2 fields read-only.

    add_action('woocommerce_checkout_fields','customization_readonly_billing_fields',10,1);
            function customization_readonly_billing_fields($checkout_fields){
                $current_user = wp_get_current_user();;
                $user_id = $current_user->ID;
                foreach ( $checkout_fields['billing'] as $key => $field ){
                    if($key == 'billing_address_1' || $key == 'billing_address_2'){
                        $key_value = get_user_meta($user_id, $key, true);
                        if( strlen($key_value)>0){
                            $checkout_fields['billing'][$key]['custom_attributes'] = array('readonly'=>'readonly');
                        }
                    }
                }
                return $checkout_fields;
            }

    Add the code to your child theme’s functions.php file or via a plugin that allows custom functions to be added, such as the Code Snippets plugin. Avoid adding custom code directly to your parent theme’s functions.php file as this will be wiped entirely when you update the theme.

    Hope this helps!

    • This reply was modified 3 years, 1 month ago by Mirko P..
    Thread Starter rawald

    (@rawald)

    Hey there and thanks so much for the reply! This only seems to work for the address it makes it readonly on the checkout as intended but the rest its allowing such as first name, last name, city etc, can’t seem to spot why the one field only is readonly

    Mirko P.

    (@rainfallnixfig)

    Hi @rawald,

    Great to hear back from you.

    This only seems to work for the address

    This is correct as the code includes the following line which will make billing_address_1 and billing_address_2 read-only:

    if($key == 'billing_address_1' || $key == 'billing_address_2'){

    You can add other fields following the advice on the same thread:

    https://stackoverflow.com/a/51101558

    Hope this helps. If you do require more help with the actual coding, we’d recommend hiring a developer or one of the customization experts listed at https://woocommerce.com/customizations/.

    Cheers.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Only Use My Account Shipping Details’ is closed to new replies.