Skip to content

fix: skip PayPal button branding when checkout does not require payment#783

Merged
superdav42 merged 1 commit intomainfrom
feature/fix-paypal-branding-free-plans
Apr 10, 2026
Merged

fix: skip PayPal button branding when checkout does not require payment#783
superdav42 merged 1 commit intomainfrom
feature/fix-paypal-branding-free-plans

Conversation

@superdav42
Copy link
Copy Markdown
Collaborator

@superdav42 superdav42 commented Apr 10, 2026

Summary

  • PayPal branding (yellow background, PayPal icon) was applied to the checkout submit button even when a free plan was selected or a 100% discount made the cart total zero
  • The branding script only checked whether the gateway data property was paypal-rest, not whether payment was actually required
  • Now checks order.should_collect_payment before applying branding, and re-evaluates whenever the form updates (product change, coupon applied, plan switch, etc.)

Changes

assets/js/gateways/paypal-rest.js:

  • Added orderRequiresPayment() — reads the same should_collect_payment flag that the payment methods template uses to show/hide the gateway selector
  • Branding now requires both conditions: PayPal selected AND payment needed
  • Added wu_on_form_updated hook listener to re-evaluate branding when the order changes (e.g. switching from paid to free plan)

Testing

  • Select a free plan on checkout → submit button should show default styling, not PayPal branding
  • Select a paid plan with PayPal → submit button should show PayPal branding
  • Switch from paid to free plan → branding should be removed
  • Apply a 100% discount code → branding should be removed
  • Remove the discount code → branding should reappear if PayPal is still selected

Summary by CodeRabbit

  • Bug Fixes
    • Fixed PayPal branding display logic to only show when PayPal is selected as the payment gateway and the order requires payment. PayPal branding now updates dynamically when order conditions change, such as coupon or product modifications.

The PayPal branding script applied yellow PayPal styling to the submit
button whenever the gateway data property was 'paypal-rest', regardless
of whether payment was actually needed. This caused free plans, 100%
discount codes, and other zero-total carts to show a PayPal-branded
submit button even though the payment section was hidden.

Now checks order.should_collect_payment before applying branding, and
re-evaluates on every form update (product change, coupon, etc.).
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 10, 2026

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 72b17889-10ea-48ff-ac76-1cbbce2d895f

📥 Commits

Reviewing files that changed from the base of the PR and between 4295272 and 2a8a680.

📒 Files selected for processing (1)
  • assets/js/gateways/paypal-rest.js

📝 Walkthrough

Walkthrough

A single JavaScript file was modified to refactor PayPal branding logic. The change decouples gateway selection from payment requirement validation, introducing conditional application of PayPal branding only when both conditions are met, with automatic refresh triggers when order conditions change.

Changes

Cohort / File(s) Summary
PayPal Branding Conditional Logic
assets/js/gateways/paypal-rest.js
Added orderRequiresPayment() to check order payment status. Replaced isPayPalActive state with isPayPalSelected (gateway selection only). Introduced refreshBranding() to compute branding eligibility based on both selection and payment requirement, managing MutationObserver activation accordingly. Updated gateway-change hook and added form-updated hook to trigger conditional refresh when order state changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A hop through the code, a clever design,
Where payment and selection in harmony align,
The branding now whispers when conditions are right,
PayPal icons appear like stars in the night,
No payment, no branding—the form grows more bright!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately summarizes the main change: skipping PayPal button branding when payment is not required, which directly addresses the core issue described in the PR objectives.
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
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix-paypal-branding-free-plans

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.

@github-actions
Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@superdav42 superdav42 merged commit da1df54 into main Apr 10, 2026
10 of 11 checks passed
@superdav42
Copy link
Copy Markdown
Collaborator Author

Summary

  • PayPal branding (yellow background, PayPal icon) was applied to the checkout submit button even when a free plan was selected or a 100% discount made the cart total zero
  • The branding script only checked whether the gateway data property was paypal-rest, not whether payment was actually required
  • Now checks order.should_collect_payment before applying branding, and re-evaluates whenever the form updates (product change, coupon applied, plan switch, etc.)

Changes

assets/js/gateways/paypal-rest.js:

  • Added orderRequiresPayment() — reads the same should_collect_payment flag that the payment methods template uses to show/hide the gateway selector
  • Branding now requires both conditions: PayPal selected AND payment needed
  • Added wu_on_form_updated hook listener to re-evaluate branding when the order changes (e.g. switching from paid to free plan)

Testing

  • Select a free plan on checkout → submit button should show default styling, not PayPal branding
  • Select a paid plan with PayPal → submit button should show PayPal branding
  • Switch from paid to free plan → branding should be removed
  • Apply a 100% discount code → branding should be removed
  • Remove the discount code → branding should reappear if PayPal is still selected

Merged via PR #783 to main.
Merged by deterministic merge pass (pulse-wrapper.sh).


aidevops.sh v3.6.235 spent 6m on this as a headless bash routine.

@github-actions
Copy link
Copy Markdown

Performance Test Results

Performance test results for 57c2c7a are in 🛎️!

Note: the numbers in parentheses show the difference to the previous (baseline) test run. Differences below 2% or 0.5 in absolute values are not shown.

URL: /

Run DB Queries Memory Before Template Template WP Total LCP TTFB LCP - TTFB
0 40 (-1 / -3% ) 37.80 MB 880.00 ms (+25.50 ms / +3% ) 168.50 ms (+11.50 ms / +7% ) 1075.50 ms (+36.50 ms / +3% ) 2042.00 ms 1960.20 ms (+44.40 ms / +2% ) 88.70 ms (-2.10 ms / -2% )
1 56 49.02 MB 924.50 ms 146.50 ms 1074.00 ms 2062.00 ms 1979.15 ms 82.10 ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant