Skip to content

fix: label saved PayPal accounts by account instead of gateway id on block checkout - #4718

Merged
Dinamiko merged 5 commits into
dev/developfrom
dev/PCP-4081-update-pay-pal-token-text-on-blocks-checkout-page
Sep 16, 2026
Merged

Dinamiko merged 5 commits into
dev/developfrom
dev/PCP-4081-update-pay-pal-token-text-on-blocks-checkout-page

Conversation

@Narek13

@Narek13 Narek13 commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

The block checkout labels a saved PayPal account as "Saved token for ppcp-gateway" — an internal ID, shown to shoppers, in English only.

WooCommerce builds that label itself, in saved-payment-method-options.tsx:

if ( method.brand && method.last4 ) {
	return sprintf( __( '%1$s ending in %2$s' ), method.brand, method.last4 );
}
return sprintf( __( 'Saved token for %s' ), method.gateway );

Both branches assume a card. A wallet token has no last4, so it always falls through to the gateway ID.

The ID is not ours to rename. In the same component method.gateway is also the payment method slug — it drives the canMakePayment filter, the input name, and the dispatch. Replacing it with a friendly string makes the token fail that check and vanish from the checkout entirely.

Changes

  • PayPal and Venmo pass the account email in the last4 slot, which is what reaches WooCommerce's readable branch. An absent email leaves last4 unset rather than rendering "PayPal ending in ".
  • brand drops its / email suffix ('PayPal / x@y.com' → 'PayPal'), since the email now lives in last4.
  • paypal => PayPal registered in woocommerce_credit_card_type_labels. wc_get_credit_card_type_label() lowercases the brand and ucfirsts what it does not recognise, so the account page rendered "Paypal" — it already did before this PR.
Before After
Block checkout Saved token for ppcp-gateway PayPal ending in name@example.com
My Account → Payment methods Paypal / name@example.com PayPal ending in name@example.com

This is a workaround, not a fix — flagged as such in the code with a TODO. Feedback is going to Woo separately: tokens need a way to supply their own label, and WC_Payment_Token::get_display_name() already returns the right string for us (PayPal / name@example.com); Blocks just never consults it.

Known limits

  • "ending in" is WooCommerce's wording, not ours, so the phrasing stays card-flavoured. Getting the requested "Use existing PayPal account" would need a JS patch fighting React re-renders, which was weighed and rejected.
  • Apple Pay is untouched — there is no sensible value to put in last4 for it, so it still shows the gateway ID.
  • Requires a WooCommerce new enough to have the brand && last4 branch. WooCommerce 8.2.2 does not: its bundle has only the gateway-ID fallback. Worth confirming against the minimum supported version — on older installs this change is simply inert, not harmful.

Backward compatibility

No signature or hook changes. Two behavioural notes:

  • $item['method']['brand'] and ['last4'] change shape for PayPal and Venmo tokens. Anything reading last4 as four digits gets an email instead — that is the trick, and it is why this is marked temporary.
  • The My Account payment methods table changes wording, as shown above. The same filter feeds both screens; keeping them consistent was deliberate. Scoping it to checkout only is a one-line guard if preferred.

Test steps

Requires a saved PayPal account (vaulting on, pay once with "save" ticked) and a current WooCommerce.

  1. Block checkout — the saved method reads "PayPal ending in name@example.com", not "Saved token for ppcp-gateway".
  2. Select it and pay — the token is still selectable and the order completes. This is the regression that matters: it proves the gateway slug was left alone.
  3. My Account → Payment methods — reads "PayPal ending in name@example.com" with a capital P.
  4. Venmo — same as 1, showing "Venmo ending in ...".
  5. Classic checkout — unchanged; it uses get_display_name(), not this list.

The block checkout showed "Saved token for ppcp-gateway" for a saved PayPal
or Venmo account. WooCommerce builds that label itself and only reaches its
readable form — "<brand> ending in <last4>" — when both fields are present;
a wallet has no card number, so it always fell back to the raw gateway id.

Pass the account email as last4 to reach the readable branch. The gateway id
is not ours to rename: the same value is the payment method slug, so changing
it drops the token out of the checkout entirely.
wc_get_credit_card_type_label() lowercases the brand and ucfirst()s whatever
it does not recognise, so the My Account payment methods table rendered
"Paypal". Register the brand so it keeps its own spelling.
The plugin's wallet token classes extend WC_Payment_Token directly, which the
suite had no stub for. Backs the meta and id accessors with instance state so
the tokens can be built without WooCommerce loaded.
Covers both filters: the account email reaching last4 for PayPal and Venmo,
an absent email leaving last4 alone rather than labelling "PayPal ending in ",
Apple Pay and unrelated token types staying as they were, and the brand label
being registered without disturbing the existing entries.
@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

🔗 Test this pull request with WordPress Playground

What's included:

  • ✅ WordPress (latest)
  • ✅ WooCommerce (latest)
  • ✅ PayPal Payments plugin v4.1.3-pr4718-34979768712-g865cfc5 (built from this PR)

Login credentials:

  • Username: admin
  • Password: password

Plugin Details:

  • Version: 4.1.3-pr4718-34979768712-g865cfc5
  • Commit: c712b60
  • Artifact: woocommerce-paypal-payments-4.1.3-pr4718-34979768712-g865cfc5

💡 The demo environment resets each time you refresh. Perfect for testing!

🔄 This link updates automatically with each new commit to the PR.

⚠️ This URL is valid for 30 days from when this comment was last updated.


🤖 Auto-generated for commit c712b60 • Last updated: 2026-09-15T14:13:51.042Z

PHPCS requires a doc comment's long description to open with a capital letter,
and this one opened on a function name.
@Dinamiko
Dinamiko merged commit 1c7fb8f into dev/develop Sep 16, 2026
12 checks passed
@Dinamiko
Dinamiko deleted the dev/PCP-4081-update-pay-pal-token-text-on-blocks-checkout-page branch September 16, 2026 10:58
@InpsydeNiklas InpsydeNiklas added this to the 4.2.0 milestone Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants