-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Fix: include billing first name in admin order search (CPT) #60279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Fix: include billing first name in admin order search (CPT) #60279
Conversation
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Note 🔌 MCP (Model Context Protocol) integration is now available in Early Access!Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
plugins/woocommerce/includes/data-stores/class-wc-order-data-store-cpt.php (2)
610-624
: Optional: Deduplicate search fields to avoid redundant IN entriesIf extensions already add these keys via the filter, duplicates can creep in. Cheap to dedupe post-assembly.
Apply after the assignment:
$search_fields = array_map( 'wc_clean', apply_filters( 'woocommerce_shop_order_search_fields', array( '_billing_address_index', '_shipping_address_index', '_billing_last_name', '_billing_first_name', '_billing_email', '_billing_phone', ) ) ); + $search_fields = array_unique( $search_fields );
600-675
: Add a regression test for CPT search by billing first nameTarget: ensure searching by billing first name returns the order even when _billing_address_index is missing (simulating older orders).
I can provide a PHPUnit test that:
- Creates an order with a unique billing first name.
- Deletes _billing_address_index post meta.
- Invokes the CPT datastore search_orders('FirstName') and asserts the ID is returned.
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
plugins/woocommerce/includes/data-stores/class-wc-order-data-store-cpt.php
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{php,js,jsx,ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/code-quality.mdc)
**/*.{php,js,jsx,ts,tsx}
: Guard against unexpected inputs
Sanitize and validate any potentially dangerous inputs
Ensure code is backwards compatible
Write code that is readable and intuitive
Ensure code has unit or E2E tests where applicable
Files:
plugins/woocommerce/includes/data-stores/class-wc-order-data-store-cpt.php
**/*.{php,js,ts,jsx,tsx}
⚙️ CodeRabbit Configuration File
**/*.{php,js,ts,jsx,tsx}
: Don't trust that extension developers will follow the best practices, make sure the code:
- Guards against unexpected inputs.
- Sanitizes and validates any potentially dangerous inputs.
- Is backwards compatible.
- Is readable and intuitive.
- Has unit or E2E tests where applicable.
Files:
plugins/woocommerce/includes/data-stores/class-wc-order-data-store-cpt.php
🧠 Learnings (3)
📓 Common learnings
Learnt from: prettyboymp
PR: woocommerce/woocommerce#60272
File: .github/workflows/release-open-issue-warning.yml:81-86
Timestamp: 2025-08-08T13:59:11.481Z
Learning: Repo: woocommerce/woocommerce — In .github/workflows/release-open-issue-warning.yml, the use of `advanced_search: true` in github.rest.search.issuesAndPullRequests is intentional and temporarily required per GitHub’s 2025-03-06 Issues Advanced Search API update. Prefer keeping it (with a brief inline comment and optional fallback) until GitHub removes the requirement.
Learnt from: NeosinneR
PR: woocommerce/woocommerce#60129
File: plugins/woocommerce/includes/wc-coupon-functions.php:145-154
Timestamp: 2025-07-31T11:18:02.478Z
Learning: In WooCommerce codebase, when table names are hardcoded (like `$wpdb->prefix . 'wc_order_coupon_lookup'`), the preference is to maintain consistency with existing patterns throughout the codebase rather than making isolated security improvements when the risk is minimal (since $wpdb->prefix is controlled by WordPress and table names are hardcoded constants).
Learnt from: nerrad
PR: woocommerce/woocommerce#60176
File: plugins/woocommerce/client/legacy/css/admin.scss:9088-9105
Timestamp: 2025-08-04T00:21:51.440Z
Learning: WooCommerce is currently in the midst of an admin redesign project, so temporary/short-term CSS solutions for admin pages are preferred over long-term refactoring when addressing immediate needs.
📚 Learning: 2025-07-31T11:18:02.478Z
Learnt from: NeosinneR
PR: woocommerce/woocommerce#60129
File: plugins/woocommerce/includes/wc-coupon-functions.php:145-154
Timestamp: 2025-07-31T11:18:02.478Z
Learning: In WooCommerce codebase, when table names are hardcoded (like `$wpdb->prefix . 'wc_order_coupon_lookup'`), the preference is to maintain consistency with existing patterns throughout the codebase rather than making isolated security improvements when the risk is minimal (since $wpdb->prefix is controlled by WordPress and table names are hardcoded constants).
Applied to files:
plugins/woocommerce/includes/data-stores/class-wc-order-data-store-cpt.php
📚 Learning: 2025-08-08T13:59:11.481Z
Learnt from: prettyboymp
PR: woocommerce/woocommerce#60272
File: .github/workflows/release-open-issue-warning.yml:81-86
Timestamp: 2025-08-08T13:59:11.481Z
Learning: Repo: woocommerce/woocommerce — In .github/workflows/release-open-issue-warning.yml, the use of `advanced_search: true` in github.rest.search.issuesAndPullRequests is intentional and temporarily required per GitHub’s 2025-03-06 Issues Advanced Search API update. Prefer keeping it (with a brief inline comment and optional fallback) until GitHub removes the requirement.
Applied to files:
plugins/woocommerce/includes/data-stores/class-wc-order-data-store-cpt.php
🔇 Additional comments (2)
plugins/woocommerce/includes/data-stores/class-wc-order-data-store-cpt.php (2)
618-621
: LGTM: Adding _billing_first_name to CPT admin search fields meets the PR objectiveThis ensures first-name searches work on older CPT orders lacking address index meta. Input and SQL are properly sanitized; no BC risk.
615-622
: No change needed – shipping first-name search already supportedThe CPT path uses
_shipping_address_index
, which concatenates shipping first name, last name, company and address fields for fulltext searches. The HPOS path also indexes and queriesfirst_name
directly:
- plugins/woocommerce/includes/data-stores/class-wc-order-data-store-cpt.php
• Thewoocommerce_shop_order_search_fields
filter includes_shipping_address_index
, covering shipping first/last names.- plugins/woocommerce/src/Internal/Utilities/DatabaseUtil.php
•CREATE FULLTEXT INDEX order_addresses_fts ON $address_table (first_name, last_name, …)
- plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableSearchQuery.php
• The search query’s SELECT/WHERE clause includesfirst_name
for HPOS.No additional shipping first-name field or HPOS follow-up is required.
Summary
Fixes admin orders search not returning results when searching by customer first name in CPT-based setups.
Changes
_billing_first_name
to the default meta keys for CPT order searches.Testing
Note
HPOS search updates not included in this PR due to branch version; can be added in follow-up if needed.