Skip to content

Fix: should_user_verify_order_email() case-sensitive email comparison#62974

Merged
mikejolley merged 7 commits intowoocommerce:trunkfrom
dev-shahed:fix/email-verification-case-insensitive
Jan 28, 2026
Merged

Fix: should_user_verify_order_email() case-sensitive email comparison#62974
mikejolley merged 7 commits intowoocommerce:trunkfrom
dev-shahed:fix/email-verification-case-insensitive

Conversation

@dev-shahed
Copy link
Copy Markdown
Contributor

Submission Review Guidelines:

Changes proposed in this Pull Request:

This PR fixes a bug where email verification for guest checkout orders was case-sensitive, causing verification failures when customers entered their email address in a different case than what was stored in the order.

Problem:
When a guest customer attempts to verify their email address to access the order payment or order received page, the comparison between the submitted email and the order's billing email was performed using strict equality (===), which is case-sensitive. This meant that if an order had a billing email of '[email protected]' and the customer entered '[email protected]', the verification would fail even though these represent the same email address.

Solution:
Changed the email comparison in Users::should_user_verify_order_email() to use strcasecmp() for case-insensitive comparison, consistent with the approach already used in OrderAuthorizationTrait::validate_billing_email_matches_order(). This ensures that email addresses are compared in a case-insensitive manner, which aligns with standard email behavior where the local part (before @) is typically treated as case-insensitive by most email providers.

Changes:

  • Modified $session_email_match comparison to use strcasecmp() instead of strict equality
  • Modified $supplied_email_match comparison to use strcasecmp() instead of strict equality
  • Added empty checks to handle null/empty values safely and prevent PHP warnings

Files changed:

  • plugins/woocommerce/src/Internal/Utilities/Users.php (lines 132-133)

Closes #62917

(For Bug Fixes) Bug introduced in PR # .

Screenshots or screen recordings:

N/A - This is a backend fix with no UI changes.

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Create a test order in WooCommerce admin:

    • Go to WooCommerce → Orders → Add New
    • Create an order with a billing email address that has mixed case (e.g., [email protected])
    • Save the order and note the order ID
    • Copy the order payment URL (format: /checkout.html/order-pay/{order_id}?pay_for_order=true&key={order_key})
  2. Wait for the grace period to expire:

    • The email verification grace period is 10 minutes by default
    • Either wait 12+ minutes, or use the filter woocommerce_order_email_verification_grace_period to set it to 0 for testing
    • Alternatively, modify the order's creation date in the database to be older than 10 minutes
  3. Test case-insensitive email verification:

    • Open the order payment URL in a private/incognito browser window (to ensure you're not logged in)
    • You should see the email verification form
    • Enter the email address in a different case than what's stored in the order (e.g., if order has [email protected], enter [email protected] or [email protected])
    • Submit the form
    • Expected: The email verification should pass and you should be able to proceed to the payment page
    • Previously (bug): The verification would fail with "We were unable to verify the email address you provided. Please try again."
  4. Test various case combinations:

  5. Test edge cases:

    • Verify that an incorrect email address still fails (e.g., [email protected])
    • Verify that empty/null email values are handled correctly
    • Test with session-based email matching (if customer has an active session)

Testing that has already taken place:

Environment:

  • Local development environment
  • WordPress with WooCommerce plugin
  • PHP 8.1+
  • Standard WooCommerce installation

Testing performed:

  • Verified that case-insensitive email comparison works correctly for all case variations
  • Confirmed that incorrect email addresses still properly fail verification
  • Tested that the fix maintains backward compatibility with existing functionality
  • Verified that empty/null email values are handled safely (prevents PHP warnings)
  • Confirmed the implementation follows WooCommerce coding standards (Yoda conditions, proper spacing)
  • Verified consistency with existing codebase patterns (matches OrderAuthorizationTrait::validate_billing_email_matches_order())
  • Code passes PHPCS linting checks

Analysis:

  • The fix uses strcasecmp() which is the standard PHP function for case-insensitive string comparison
  • This approach is already used elsewhere in WooCommerce for email comparison (Store API)
  • The change is minimal and focused, reducing risk of side effects
  • Added empty checks ensure null/empty values don't cause PHP warnings while maintaining original behavior

Milestone

Note: Check the box above to have the milestone automatically assigned when merged.
Alternatively (e.g. for point releases), manually assign the appropriate milestone.

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Fixed case-sensitive email verification issue that prevented guests from accessing order payment pages when entering their email address in a different case than stored in the order.

Changelog Entry Comment

Comment

Resolve BlocksUtil conflict: keep upstream null-check (null === template->content).
…sensitive comparison and non-empty checks for session and supplied emails.
@github-actions github-actions bot added plugin: woocommerce Issues related to the WooCommerce Core plugin. type: community contribution labels Jan 27, 2026
@woocommercebot woocommercebot requested review from a team and albarin and removed request for a team January 27, 2026 04:26
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 27, 2026

Testing Guidelines

Hi @woocommerce/rubik,

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

  • 🖼️ Screenshots or screen recordings.
  • 📝 List of functionality tested / steps followed.
  • 🌐 Site details (environment attributes such as hosting type, plugins, theme, store size, store age, and relevant settings).
  • 🔍 Any analysis performed, such as assessing potential impacts on environment attributes and other plugins, conducting performance profiling, or using LLM/AI-based analysis.

⚠️ Within the testing details you provide, please ensure that no sensitive information (such as API keys, passwords, user data, etc.) is included in this public issue.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 27, 2026

Caution

Review failed

The head commit changed during the review from 4ee8b0d to f1c8e13.

📝 Walkthrough

Walkthrough

Updates WooCommerce utilities: makes email comparisons case-insensitive with empty-value guards in the Users utility, changes a template content null-check to an empty check in BlocksUtil, and adds a patch changelog entry describing the fix for guest order payment access when email case differs.

Changes

Cohort / File(s) Summary
Email Verification Case-Insensitive Fix
plugins/woocommerce/src/Internal/Utilities/Users.php
Replaced direct email equality checks with strcasecmp() for case-insensitive comparison and added !empty() guards for session_email_match and supplied_email_match.
Template Content Check Update
plugins/woocommerce/src/Internal/Utilities/BlocksUtil.php
Changed guard in get_block_from_template_part from null === $template->content to empty( $template->content ), treating empty content as missing.
Changelog Documentation
plugins/woocommerce/changelog/62974-fix-email-verification-case-insensitive
Added a patch-level changelog entry documenting the case-insensitive email verification fix preventing guest access to order payment pages.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing case-sensitive email comparison in the should_user_verify_order_email() function.
Description check ✅ Passed The description clearly explains the bug, the solution, and provides comprehensive testing instructions that relate directly to the changeset.
Linked Issues check ✅ Passed The PR successfully addresses issue #62917 by implementing case-insensitive email comparison using strcasecmp() in Users.php, fulfilling the core requirement that guest email verification should pass when emails differ only by case.
Out of Scope Changes check ✅ Passed All changes directly support the case-insensitive email verification objective. The BlocksUtil.php change to empty-check appears narrowly focused and minimal; the changelog entry properly documents the patch fix.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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: 1

🤖 Fix all issues with AI agents
In `@plugins/woocommerce/src/Internal/Utilities/BlocksUtil.php`:
- Around line 68-78: Remove the Git merge conflict markers and keep the branch
that uses the empty() check for the template content: replace the conflicting
block (the lines with <<<<<<<, =======, >>>>>>>) in the conditional that checks
$template->content with a single if that uses empty( $template->content ) and
returns array() when true; ensure the resulting code in BlocksUtil (the
conditional around $template->content) has no leftover conflict markers and
preserves the return array() behavior.

Comment thread plugins/woocommerce/src/Internal/Utilities/BlocksUtil.php Outdated
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 27, 2026

@dev-shahed: I'll review the PR changes for you now.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@albarin albarin requested review from a team, mikejolley, opr and rubikuserbot and removed request for albarin and rubikuserbot January 28, 2026 11:32
Copy link
Copy Markdown
Member

@mikejolley mikejolley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for providing the fix. I'm happy with this solution so this can be merged once the CI is passing 👍🏻

@mikejolley mikejolley merged commit 4e939fa into woocommerce:trunk Jan 28, 2026
48 of 49 checks passed
@github-actions github-actions bot added this to the 10.6.0 milestone Jan 28, 2026
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.

should_user_verify_order_email() email address check is case sensitive does it need it be?

3 participants