1

Is there a way to disable users from editing their billing address in checkout page?

I'm trying to achieve a state where the user can see the current billing address but cannot change it without contacting the shop admin. The user can only change the shipping address for the order. Both addresses should still be attached to the order.

My current solution was to remove the fields completely by using the woocommerce_billing_fields hook and print the billing address fields as static html instead but then the billing address doesn't appear in the order at all.

1 Answer 1

3

Okay I found a solution after Slack conversation. It is possible to remove the fields from checkout by unsetting them in woocommerce_billing_fields hook and then re-adding the values again to the order from users profile with woocommerce_checkout_posted_data hook.

add_filter( 'woocommerce_checkout_posted_data', 'fill_order_billing_details' );

function fill_order_billing_details( $data ) {
  $customer_id = get_current_user_id();

  $data['billing_first_name'] = get_user_meta( $customer_id, 'billing_first_name', true );
  $data['billing_last_name']  = get_user_meta( $customer_id, 'billing_last_name', true );
  $data['billing_company']    = get_user_meta( $customer_id, 'billing_company', true );
  $data['billing_country']    = get_user_meta( $customer_id, 'billing_country', true );
  $data['billing_address_1']  = get_user_meta( $customer_id, 'billing_address_1', true );
  $data['billing_address_2']  = get_user_meta( $customer_id, 'billing_address_2', true );
  $data['billing_city']       = get_user_meta( $customer_id, 'billing_city', true );
  $data['billing_state']      = get_user_meta( $customer_id, 'billing_state', true );
  $data['billing_postcode']   = get_user_meta( $customer_id, 'billing_postcode', true );
  $data['billing_phone']      = get_user_meta( $customer_id, 'billing_phone', true );
  $data['billing_email']      = get_user_meta( $customer_id, 'billing_email', true );

  return $data;
}
2
  • How can I do that for certain user roles only? Sep 27, 2019 at 13:35
  • Not a bad idea.. Apr 12, 2022 at 20:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.