Fix V4 Customers API requiring username/password based on store settings#63536
Conversation
Store registration settings (woocommerce_registration_generate_username, woocommerce_registration_generate_password) should only affect frontend registration forms, not the admin-facing REST API. This makes username and password always optional in the V4 Customers endpoint, with auto-generation when not provided. Also fixes the customer data store to sync back the auto-generated username from the WP user after creation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Testing GuidelinesApart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed. Reminder: PR reviewers are required to document testing performed. This includes:
|
📝 WalkthroughWalkthroughThis patch fix makes username and password optional in the V4 Customers REST API regardless of store registration settings. The customer creation flow now syncs data from auto-generated WP users, schemas are updated to reflect non-required fields, and test coverage validates the behavior. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Test using WordPress PlaygroundThe changes in this pull request can be previewed and tested using a WordPress Playground instance. Test this pull request with WordPress Playground. Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit. |
senadir
left a comment
There was a problem hiding this comment.
Can this cause some sort of locked out state for customers? If password is autogenerated, how will they receive it? I think they would need to reset it.
|
@senadir Yeah but I would expect the consumer to take care of that. This is an admin facing API. |
…ngs (#63536) Store registration settings (woocommerce_registration_generate_username, woocommerce_registration_generate_password) should only affect frontend registration forms, not the admin-facing REST API. This makes username and password always optional in the V4 Customers endpoint, with auto-generation when not provided. Also fixes the customer data store to sync back the auto-generated username from the WP user after creation. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
…ngs (#63536) Store registration settings (woocommerce_registration_generate_username, woocommerce_registration_generate_password) should only affect frontend registration forms, not the admin-facing REST API. This makes username and password always optional in the V4 Customers endpoint, with auto-generation when not provided. Also fixes the customer data store to sync back the auto-generated username from the WP user after creation. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Submission Review Guidelines:
Changes proposed in this Pull Request:
The V4 Customers REST API endpoint incorrectly ties the
requiredstatus ofusernameandpasswordparameters to frontend store registration settings (woocommerce_registration_generate_usernameandwoocommerce_registration_generate_password). This means that when these settings disable auto-generation (intended for frontend registration forms), the admin API also rejects requests without username/password, which is unexpected.This is an admin-facing API — store registration settings should only affect frontend user registration forms, not API consumers.
Changes:
Controller (
src/Internal/RestApi/Routes/V4/Customers/Controller.php): Makeusernameandpasswordalways optional (required: false) by removing theget_option()checks from route registration.Data Store (
includes/data-stores/class-wc-customer-data-store.php): Afterwc_create_new_customer()creates the WP user (auto-generating username/password when empty), sync the generated username back to theWC_Customerobject. Previously only the ID was set back, leaving the customer object with an empty username in the response.Test: Added
test_create_customer_without_username_or_passwordverifying that customer creation succeeds with only an email, even when store settings have auto-generation disabled.Closes #WOOPRD-1726.
Screenshots or screen recordings:
N/A
How to test the changes in this Pull Request:
woocommerce_registration_generate_usernametonoandwoocommerce_registration_generate_passwordtonovia the database/WP CLI./wp-json/wc/v4/customerswith only{ "email": "test@example.com" }(no username or password) using admin authentication.Testing that has already taken place:
test_create_customer_without_username_or_passwordpasses.Milestone
Changelog entry
Changelog Entry Details
Significance
Type
Message
Make username and password optional in V4 Customers REST API regardless of store registration settings.