Skip to content

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

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

ritunaik0904
Copy link

Summary
Fixes admin orders search not returning results when searching by customer first name in CPT-based setups.

Changes

  • Added _billing_first_name to the default meta keys for CPT order searches.

Testing

  • Create orders with unique billing first names, search for those names in WooCommerce admin Orders list — orders should appear.

Note
HPOS search updates not included in this PR due to branch version; can be added in follow-up if needed.

@github-actions github-actions bot added type: community contribution plugin: woocommerce Issues related to the WooCommerce Core plugin. labels Aug 8, 2025
Copy link
Contributor

coderabbitai bot commented Aug 8, 2025

📝 Walkthrough

Walkthrough

The search_orders method in the WooCommerce order data store was updated to include _billing_first_name as a searchable meta key. The order and grouping of the search fields were adjusted, and minor formatting changes were made. No public interfaces or method signatures were changed.

Changes

Cohort / File(s) Change Summary
Order Search Meta Keys Update
plugins/woocommerce/includes/data-stores/class-wc-order-data-store-cpt.php
Modified the array of meta keys used for searching orders: added _billing_first_name before _billing_email and _billing_phone; adjusted formatting.

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 Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 entries

If 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 name

Target: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 348045d and 9eaad06.

📒 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 objective

This 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 supported

The 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 queries first_name directly:

  • plugins/woocommerce/includes/data-stores/class-wc-order-data-store-cpt.php
    • The woocommerce_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 includes first_name for HPOS.

No additional shipping first-name field or HPOS follow-up is required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: woocommerce Issues related to the WooCommerce Core plugin. type: community contribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant