Skip to content
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

update: payment method test mode label behavior #9647

Merged
merged 13 commits into from
Nov 7, 2024

Conversation

frosso
Copy link
Contributor

@frosso frosso commented Oct 30, 2024

Fixes #9625

Changes proposed in this Pull Request

Updated the "Test mode" badge to be displayed only when the payment method is selected.
I kept (but slightly modified) the grid layout.
I attempted a flexbox implementation, but ran out of options. The main challenge was showing the BNPL messaging on a new line, together with the card icon. I was semi-successful if I placed the card icon on position: absolute and the label on position: relative, but it was becoming less maintainable.

Changes are mainly UI-based, so unit tests are less effective.

Testing instructions

  • Add some products to the cart
  • Go to shortcode (or block-based) checkout
  • Ensure that the "Test mode" label is displayed on WooPayments payment methods only when the payment method is selected
  • As a customer, navigate to the "My account > Add payment method" page
  • Ensure that the "Test mode" label is displayed on WooPayments payment methods only when the payment method is selected
  • As a customer, ensure you have active subscriptions (create one if you don't)
  • Navigate to "My account > Subscriptions > Select an 'active' subscription > Click 'Change payment'"
  • Ensure that the "Test mode" label is not displayed

  • Run npm run changelog to add a changelog file, choose patch to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.
  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Post merge

@botwoo
Copy link
Collaborator

botwoo commented Oct 30, 2024

Test the build

Option 1. Jetpack Beta

  • Install and activate Jetpack Beta.
  • Use this build by searching for PR number 9647 or branch name update/payment-method-test-mode-label in your-test.site/wp-admin/admin.php?page=jetpack-beta&plugin=woocommerce-payments

Option 2. Jurassic Ninja - available for logged-in A12s

🚀 Launch a JN site with this branch 🚀

ℹ️ Install this Tampermonkey script to get more options.


Build info:

  • Latest commit: 15661b4
  • Build time: 2024-11-07 09:37:08 UTC

Note: the build is updated when a new commit is pushed to this PR.

Copy link
Contributor

github-actions bot commented Oct 30, 2024

Size Change: +112 B (0%)

Total Size: 1.33 MB

Filename Size Change
release/woocommerce-payments/dist/blocks-checkout-rtl.css 2.66 kB +18 B (+1%)
release/woocommerce-payments/dist/blocks-checkout.css 2.66 kB +18 B (+1%)
release/woocommerce-payments/dist/blocks-checkout.js 58.1 kB +88 B (0%)
release/woocommerce-payments/dist/checkout-rtl.css 1.23 kB +21 B (+2%)
release/woocommerce-payments/dist/checkout.css 1.23 kB +20 B (+2%)
release/woocommerce-payments/dist/checkout.js 33 kB -53 B (0%)
ℹ️ View Unchanged
Filename Size
release/woocommerce-payments/assets/css/admin.css 1.37 kB
release/woocommerce-payments/assets/css/admin.rtl.css 1.37 kB
release/woocommerce-payments/assets/css/success.css 173 B
release/woocommerce-payments/assets/css/success.rtl.css 173 B
release/woocommerce-payments/dist/cart-block.js 16.8 kB
release/woocommerce-payments/dist/cart.js 5.73 kB
release/woocommerce-payments/dist/express-checkout-rtl.css 230 B
release/woocommerce-payments/dist/express-checkout.css 230 B
release/woocommerce-payments/dist/express-checkout.js 14.9 kB
release/woocommerce-payments/dist/frontend-tracks.js 858 B
release/woocommerce-payments/dist/index-rtl.css 39.3 kB
release/woocommerce-payments/dist/index.css 39.3 kB
release/woocommerce-payments/dist/index.js 302 kB
release/woocommerce-payments/dist/multi-currency-analytics.js 1.08 kB
release/woocommerce-payments/dist/multi-currency-rtl.css 4.46 kB
release/woocommerce-payments/dist/multi-currency-switcher-block.js 60.6 kB
release/woocommerce-payments/dist/multi-currency.css 4.46 kB
release/woocommerce-payments/dist/multi-currency.js 57.3 kB
release/woocommerce-payments/dist/order-rtl.css 730 B
release/woocommerce-payments/dist/order.css 730 B
release/woocommerce-payments/dist/order.js 42 kB
release/woocommerce-payments/dist/payment-gateways-rtl.css 1.32 kB
release/woocommerce-payments/dist/payment-gateways.css 1.32 kB
release/woocommerce-payments/dist/payment-gateways.js 38.4 kB
release/woocommerce-payments/dist/payment-request-rtl.css 230 B
release/woocommerce-payments/dist/payment-request.css 230 B
release/woocommerce-payments/dist/payment-request.js 14.2 kB
release/woocommerce-payments/dist/plugins-page-rtl.css 386 B
release/woocommerce-payments/dist/plugins-page.css 386 B
release/woocommerce-payments/dist/plugins-page.js 20.1 kB
release/woocommerce-payments/dist/product-details-rtl.css 433 B
release/woocommerce-payments/dist/product-details.css 436 B
release/woocommerce-payments/dist/product-details.js 12.1 kB
release/woocommerce-payments/dist/settings-rtl.css 11.6 kB
release/woocommerce-payments/dist/settings.css 11.5 kB
release/woocommerce-payments/dist/settings.js 224 kB
release/woocommerce-payments/dist/subscription-edit-page.js 703 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal-rtl.css 524 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.css 524 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.js 20.2 kB
release/woocommerce-payments/dist/subscription-product-onboarding-toast.js 730 B
release/woocommerce-payments/dist/subscriptions-empty-state-rtl.css 120 B
release/woocommerce-payments/dist/subscriptions-empty-state.css 120 B
release/woocommerce-payments/dist/subscriptions-empty-state.js 19.3 kB
release/woocommerce-payments/dist/tokenized-payment-request-rtl.css 230 B
release/woocommerce-payments/dist/tokenized-payment-request.css 230 B
release/woocommerce-payments/dist/tokenized-payment-request.js 15 kB
release/woocommerce-payments/dist/tos-rtl.css 235 B
release/woocommerce-payments/dist/tos.css 235 B
release/woocommerce-payments/dist/tos.js 21.8 kB
release/woocommerce-payments/dist/woopay-direct-checkout.js 6.14 kB
release/woocommerce-payments/dist/woopay-express-button.js 24.6 kB
release/woocommerce-payments/dist/woopay-rtl.css 4.52 kB
release/woocommerce-payments/dist/woopay.css 4.49 kB
release/woocommerce-payments/dist/woopay.js 71.6 kB
release/woocommerce-payments/includes/subscriptions/assets/css/plugin-page.css 625 B
release/woocommerce-payments/includes/subscriptions/assets/js/plugin-page.js 814 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/i18n-loader.js 2.46 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/jetpack-script-data.js 735 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/react-jsx-runtime.js 553 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/i18n-loader.js 1.02 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/script-data.js 69 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/babel.config.js 163 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.css 2.45 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.js 14.2 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.rtl.css 2.45 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.css 198 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.js 280 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.rtl.css 198 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.css 625 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.js 333 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.rtl.css 626 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-users.js 417 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-ajax.js 521 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-callables.js 584 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-admin-create-user.css 215 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-admin-create-user.js 521 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-login.css 721 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-login.js 412 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-users.js 621 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/about.css 1.04 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-empty-state.css 294 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-order-statuses.css 408 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin.css 3.59 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/checkout.css 301 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/modal.css 746 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/view-subscription.css 574 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/wcs-upgrade.css 414 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin-pointers.js 543 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin.js 9.4 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.js 6.78 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.min.js 3.84 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-coupon.js 545 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-subscription.js 2.52 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.js 22.2 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.min.js 11.7 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/payment-method-restrictions.js 1.29 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/wcs-meta-boxes-order.js 507 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/payment-methods.js 358 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/single-product.js 428 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/view-subscription.js 1.38 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/wcs-cart.js 782 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/modal.js 1.09 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/wcs-upgrade.js 1.26 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.css 391 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.js 3.04 kB

compressed-size-action

@frosso frosso marked this pull request as ready for review October 30, 2024 15:34
@frosso frosso requested review from a team and danielmx-dev and removed request for a team October 30, 2024 15:36

<?php if ( WC_Payments::mode()->is_test() ) : ?>
if ( WC_Payments::mode()->is_test() && false !== $this->gateway->get_payment_method()->get_testing_instructions() ) :
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated this so that the div.testmode-info element will be shown only if test instructions are present - otherwise it's displayed even on Klarna, Affirm, etc.

Comment on lines -137 to -139
$script = 'dist/checkout';

WC_Payments::register_script_with_dependencies( 'wcpay-upe-checkout', $script, $script_dependencies );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inlined the $script, since it's not used anywhere else

@@ -58,7 +58,7 @@ public function get_payment_method_script_handles() {
'wc-blocks-checkout-style',
plugins_url( 'dist/blocks-checkout.css', WCPAY_PLUGIN_FILE ),
[],
'1.0',
WC_Payments::get_file_version( 'dist/checkout.css' ),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Getting the version from the build file, so that it changes at each release and we can effectively cache bust it - otherwise we incur the risk of providing an older build (because it could be cached by the customer's browser or the merchant's CDN)

@@ -581,16 +581,15 @@ public function get_title() {
$title = parent::get_title();

if (
Payment_Method::CARD === $this->stripe_id &&
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The "Test mode" badge is now displayed on all methods, when test mode is enabled. It'll be displayed by CSS only when the payment method is selected.

}

.test-mode.badge {
display: inline-block;
display: none;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not displaying it by default - it'll be displayed only when the method is selected.

}
}

li.wc_payment_method:has( .input-radio:not( :checked )
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved above - the different structure shouldn't be needed anymore.

width: 100%;
&__pmme-container {
width: 100%;
pointer-events: none;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to ensure that clicking on the Payment Method Messaging Element expands the payment method

Comment on lines +113 to +116
title={ upeConfig.title }
countries={ upeConfig.countries }
iconLight={ upeConfig.icon }
iconDark={ upeConfig.darkIcon }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just like to be explicit 🤷

Copy link
Contributor

@danielmx-dev danielmx-dev left a comment

Choose a reason for hiding this comment

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

Most changes look good, but I found an issue when trying to use a theme that doesn't hides the original input element (e.g. twenty-twentyfour)

@@ -12,9 +12,50 @@ import './style.scss';
import { useEffect, useState } from '@wordpress/element';
import { getAppearance } from 'wcpay/checkout/upe-styles';

export default ( { api, upeConfig, upeName, upeAppearanceTheme } ) => {
const bnplMethods = [ 'affirm', 'afterpay_clearpay', 'klarna' ];
const PaymentMethodMessageWrapper = ( {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be on its own file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I personally don't think so, because it's not going to be used anywhere else - I just extracted it from the previous implementation because I thought it would make things slightly easier to scroll through, since there are a lot of if conditions to check for. 🤷

Comment on lines 44 to 48
li.payment_method_woocommerce_payments {
display: grid;
grid-template-columns: 0fr 0fr 1fr;
grid-template-rows: max-content;

Copy link
Contributor

Choose a reason for hiding this comment

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

I originally used grid on the li element to prevent layout issues with themes that don't hide the input[type=radio] element and replace it with a custom ::before icon in the label.

If you switch to a theme like twenty-twentyfour you'll see that the layout is broken due to this.

image

This is how it looks like in develop.
image

Copy link
Contributor Author

@frosso frosso left a comment

Choose a reason for hiding this comment

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

Thank you for catching that bug @danielmx-dev ! I think I got that covered, let me know what you think!
I ended up having to change the markup, and create a wrapper (with display: grid) for all the elements we want to display.
I found this approach to be working a little better across different themes, it was quite the headache 😅

Examples

Screenshot 2024-11-06 at 5 57 35 PM Screenshot 2024-11-06 at 5 49 01 PM Screenshot 2024-11-06 at 5 48 28 PM Screenshot 2024-11-06 at 5 48 19 PM Screenshot 2024-11-06 at 5 48 13 PM Screenshot 2024-11-06 at 5 48 09 PM Screenshot 2024-11-06 at 5 47 42 PM Screenshot 2024-11-06 at 5 47 37 PM Screenshot 2024-11-06 at 5 47 33 PM Screenshot 2024-11-06 at 5 45 45 PM Screenshot 2024-11-06 at 5 45 36 PM Screenshot 2024-11-06 at 5 44 49 PM Screenshot 2024-11-06 at 5 44 21 PM Screenshot 2024-11-06 at 5 44 12 PM

}

if ( targetLabel ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing this slightly - the container will always be present (generated from the backend), the JS will use it to mount the BNPL messaging.

Comment on lines +591 to +609

$bnpl_messaging_container = '';
if ( $this->payment_method->is_bnpl() ) {
$bnpl_messaging_container = '<span id="stripe-pmme-container-' . $this->payment_method->get_id() . '" class="stripe-pmme-container"></span>';
}

// the "plain" payment method label is displayed on some sections of the app
// - like "pay for order" when a payment method is pre-selected or a payment has previously failed.
$html = '<span class="woopayments-plain-payment-method-label">' . $title . '</span>';
$html .= '<div class="woopayments-rich-payment-method-label">';
$html .= '<div class="label-title-container">';
$html .= '<span class="payment-method-title">&nbsp;' . $title . '</span>';
$html .= $test_mode_badge;
$html .= '</div>';
$html .= $this->get_icon();
$html .= $bnpl_messaging_container;
$html .= '</div>';

return $html;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing the previous approach a bit - I'm now rendering two elements: a "rich" and a "plain" element.
It turns out that the pay-for-order page will use this method to render the payment method (if a previous attempt failed).

So I need to render both labels and (via CSS) selectively hide/show the most appropriate one based on the context the label is displayed.

@@ -12,9 +12,50 @@ import './style.scss';
import { useEffect, useState } from '@wordpress/element';
import { getAppearance } from 'wcpay/checkout/upe-styles';

export default ( { api, upeConfig, upeName, upeAppearanceTheme } ) => {
const bnplMethods = [ 'affirm', 'afterpay_clearpay', 'klarna' ];
const PaymentMethodMessageWrapper = ( {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I personally don't think so, because it's not going to be used anywhere else - I just extracted it from the previous implementation because I thought it would make things slightly easier to scroll through, since there are a lot of if conditions to check for. 🤷

@frosso frosso requested a review from danielmx-dev November 6, 2024 17:27
@frosso
Copy link
Contributor Author

frosso commented Nov 6, 2024

I forgot to mention that the radio button's circle is now displayed centered when the payment method is rendered in multiple lines, like for BNPLs:
Screenshot 2024-11-06 at 6 30 36 PM

The behavior seems to be consistent with the blocks checkout:
Screenshot 2024-11-06 at 6 32 18 PM

@danielmx-dev
Copy link
Contributor

@frosso It looks like the hidden label is causing issues with the playwright tests.

Error: locator.click: Error: strict mode violation: locator('.wc_payment_methods').getByText('Klarna') resolved to 2 elements:
    1) <span class="woopayments-plain-payment-method-label">Klarna</span> aka locator('span').filter({ hasText: /^Klarna$/ })
    2) <span class="payment-method-title"> Klarna</span> aka getByText('Klarna').nth(1)

You may need to check the visibility or match using a different locator to fix the tests.

@danielmx-dev
Copy link
Contributor

I have tested different scenarios using both themes (Storefront and Twenty twenty-four) and they all look good!

✅ Classic Checkout
✅ Blocks Checkout
✅ Pay For Order
✅ Add Payment Method
✅ Change Payment Method (Subscription)

I can approve this once the issue with the Playwright tests is resolved.

@frosso
Copy link
Contributor Author

frosso commented Nov 7, 2024

@danielmx-dev thank you - that was a good call.
I also ended up running the full suite of e2e tests, which passed: https://github.com/Automattic/woocommerce-payments/actions/runs/11720280701

Copy link
Contributor

@danielmx-dev danielmx-dev left a comment

Choose a reason for hiding this comment

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

Looks good! 🚢

xPathPaymentMethodSelector
);
await paymentMethodLabel.click();
await selectOnCheckout( providerId, page );
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for refactoring this, I know this suite in particular is flaky so hopefully this improves the reliability.

@frosso frosso added this pull request to the merge queue Nov 7, 2024
Merged via the queue into develop with commit 636e1f0 Nov 7, 2024
42 checks passed
@frosso frosso deleted the update/payment-method-test-mode-label branch November 7, 2024 13:58
@pierorocca
Copy link
Contributor

For the record, are the labels still offset?

@frosso
Copy link
Contributor Author

frosso commented Nov 7, 2024

@pierorocca the labels should be consistently spaced at checkout.

Here's an example with WooCommerce Core, WooPayments, and WooCommerce Stripe payment methods displayed at checkout on two different themes:
Screenshot 2024-11-07 at 4 21 41 PM
Screenshot 2024-11-07 at 4 23 06 PM

@pierorocca
Copy link
Contributor

Cool ty!

@pierorocca
Copy link
Contributor

I've noticed on mobile the logo vertically centered alignment does have an impact on text wrapping. Mind adding a 375px viewport example?

@frosso
Copy link
Contributor Author

frosso commented Nov 7, 2024

@pierorocca sure - these are a couple of examples on Storefront and TT4 with different payment methods selected (to showcase the label wrapping). I specifically hid some of the payment elements for the sake of ensuring things fit into the vertical space within the screenshot.

Screenshot 2024-11-07 at 6 16 54 PM Screenshot 2024-11-07 at 6 16 48 PM Screenshot 2024-11-07 at 6 05 53 PM Screenshot 2024-11-07 at 6 05 28 PM

EDIT: I re-uploaded the TT4 screenshots because I had some local changes affecting the result.

@pierorocca
Copy link
Contributor

pierorocca commented Nov 7, 2024

Is there a bnpl example that shows the full offer detail copy with $ amounts? Ty.

@frosso
Copy link
Contributor Author

frosso commented Nov 8, 2024

@pierorocca sure, here's an example with Storefront at 375px with the messaging and the "test mode" pill added/removed:
Screenshot 2024-11-08 at 9 12 41 AM
Screenshot 2024-11-08 at 9 12 37 AM

@morepurplemorebetter
Copy link

Why does this add a &nbsp; in front of the payment method's name?
This way, they no longer align with other payment methods (i.e. non-WooPayments).
Wouldn't it be better to achieve this with css?

@frosso
Copy link
Contributor Author

frosso commented Nov 21, 2024

Hi @morepurplemorebetter ! 👋 I agree that CSS would have been a better option, but WooCommerce core adds the whitespace next to the payment method's name on its shortcode checkout core template, so we needed to reflect the same implementation for the shortcode checkout: https://github.com/woocommerce/woocommerce/blob/c051a5755c2a15d92c57d6444803afc71a4f6696/plugins/woocommerce/templates/checkout/payment-method.php#L25-L27

Keep in mind that the &nbsp; was added even before these specific changes:

return '<div class="label-title-container"><span class="payment-method-title">&nbsp;' . $title . '</span>' . $test_mode_badge . '</div>';

Do you happen to have some examples of specific gateways and/or themes that are being affected?

We tested these changes with a mix of core and non-core gateways and themes, but we'd be happy to make some efforts to expand compatibility!

For reference, these are screenshots of Storefront/TT4/TT3/Elementor with a mix of gateways:
Screenshot 2024-11-21 at 12 09 50 PM
Screenshot 2024-11-21 at 12 08 44 PM
Screenshot 2024-11-21 at 12 12 01 PM
Screenshot 2024-11-21 at 12 15 42 PM

EDIT: another suggestion: since the change is mainly esthetic when test mode is enabled, we could even add a filter to dynamically enable/disable the changes, doing a fallback to core WooCommerce.

@morepurplemorebetter
Copy link

Hi @frosso, thank you for such a complete and in-depth answer.

After some investigation this seems indeed to be something with my theme, because it doesn't show the <input> radio buttons, but uses a custom <span> element instead. As a result, the whitespace between that span and the label is not rendered, but the &nbsp; is.

Would it otherwise be possible to replace it with actual whitespace between the elements so that it matches the core implementation both in visual and in behaviour?

 

Keep in mind that the   was added even before these specific changes:

Apologies, I didn't notice that it was introduced with #9495. That change was also pretty recent (v8.4.0) and I just updated my staging environment from WooPayments v8.2.2 to v8.5.0, so I skipped that particular edit.

 

another suggestion: since the change is mainly esthetic when test mode is enabled, we could even add a filter to dynamically enable/disable the changes, doing a fallback to core WooCommerce.

The option to disable this new 'html' type of payment method title would be a great addition, because it would also solve my biggest issue with this PR: #9779

@frosso
Copy link
Contributor Author

frosso commented Nov 21, 2024

Hey @morepurplemorebetter , I have a little bit of an update!

I opened a PR that should land in our next version (8.6.0), which is currently scheduled to be released on Dec 4, 2024.
That PR adds a filter to enable/disable the "rich" payment method label in all scenarios.
Adding this filter should completely disable it for your theme:

add_filter( 'wcpay_checkout_use_plain_method_label', '__return_true' );

We're currently discussing different ways to implement a similar visual outcome, fixing it also for the email templates like you mentioned here: #9779
But, if instead you had already a fix for your theme, and you just wanted to fix it in your email templates, you could add this filter (which seems to be fixing it for email templates):

add_filter( 'wcpay_checkout_use_plain_method_label', 'is_ajax' );

I hope this helps!

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.

Apply test badge to payment component when it has focus
5 participants