Skip to content

Commit 835a101

Browse files
authored
Fix WooPay opt-in blocks field (#9131)
1 parent 995198e commit 835a101

File tree

8 files changed

+99
-4
lines changed

8 files changed

+99
-4
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fix
3+
4+
Fix WooPay opt-in blocks field on WooCommerce 9.1+.

client/checkout/woopay/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const renderSaveUserSection = () => {
3939
paymentOptions.nextSibling
4040
);
4141

42+
paymentOptions.classList.add( 'is-woopay' );
43+
4244
ReactDOM.render(
4345
<CheckoutPageSaveUser isBlocksCheckout={ true } />,
4446
checkoutPageSaveUserContainer

client/components/woopay/save-user/checkout-page-save-user.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import useWooPayUser from '../hooks/use-woopay-user';
1919
import useSelectedPaymentMethod from '../hooks/use-selected-payment-method';
2020
import { recordUserEvent } from 'tracks';
2121
import './style.scss';
22+
import { compare } from 'compare-versions';
2223

2324
const CheckoutPageSaveUser = ( { isBlocksCheckout } ) => {
2425
const [ isSaveDetailsChecked, setIsSaveDetailsChecked ] = useState(
@@ -34,6 +35,12 @@ const CheckoutPageSaveUser = ( { isBlocksCheckout } ) => {
3435
);
3536
const viewportWidth = window.document.documentElement.clientWidth;
3637
const viewportHeight = window.document.documentElement.clientHeight;
38+
const wooCommerceVersionString = window.wcSettings?.wcVersion;
39+
const wcVersionGreaterThan91 = compare(
40+
wooCommerceVersionString,
41+
'9.1',
42+
'>='
43+
);
3744

3845
const getPhoneFieldValue = () => {
3946
let phoneFieldValue = '';
@@ -174,7 +181,10 @@ const CheckoutPageSaveUser = ( { isBlocksCheckout } ) => {
174181
}
175182

176183
return (
177-
<Container isBlocksCheckout={ isBlocksCheckout }>
184+
<Container
185+
isBlocksCheckout={ isBlocksCheckout }
186+
wcVersionGreaterThan91={ wcVersionGreaterThan91 }
187+
>
178188
<div className="save-details">
179189
<div className="save-details-header">
180190
<div
@@ -193,6 +203,10 @@ const CheckoutPageSaveUser = ( { isBlocksCheckout } ) => {
193203
id="save_user_in_woopay"
194204
value="true"
195205
className={ `save-details-checkbox ${
206+
wcVersionGreaterThan91
207+
? 'without-margin-right'
208+
: ''
209+
} ${
196210
isBlocksCheckout
197211
? 'wc-block-components-checkbox__input'
198212
: ''

client/components/woopay/save-user/container.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@
33
*/
44
import { __ } from '@wordpress/i18n';
55

6-
const Container = ( { children, isBlocksCheckout } ) => {
6+
const Container = ( {
7+
children,
8+
isBlocksCheckout,
9+
wcVersionGreaterThan91,
10+
} ) => {
711
if ( ! isBlocksCheckout ) return children;
812
return (
913
<>
10-
<div className="woopay-save-new-user-container">
14+
<div
15+
className={ `woopay-save-new-user-container ${
16+
wcVersionGreaterThan91 ? 'wc-version-greater-than-91' : ''
17+
}` }
18+
>
1119
<h2>{ __( 'Save my info' ) }</h2>
1220
{ children }
1321
</div>

client/components/woopay/save-user/style.scss

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,53 @@
77
}
88
}
99

10+
.is-mobile,
11+
.is-small {
12+
.woopay-save-new-user-container.wc-version-greater-than-91::after {
13+
background: currentColor;
14+
box-shadow: -50vw 0 0 0 currentColor, 50vw 0 0 0 currentColor;
15+
content: '';
16+
height: 1px;
17+
opacity: 0.11;
18+
width: 100%;
19+
margin-top: 22px;
20+
}
21+
}
22+
23+
.is-medium,
24+
.is-large {
25+
.woopay-save-new-user-container.wc-version-greater-than-91 {
26+
border-bottom: 1px solid hsla( 0, 0%, 7%, 0.11 );
27+
margin-bottom: 48px;
28+
}
29+
}
30+
31+
@media ( max-width: 600px ) {
32+
.is-mobile,
33+
.is-small {
34+
.wc-block-components-form
35+
.wc-block-components-checkout-step.is-woopay::after {
36+
height: 0;
37+
}
38+
}
39+
}
40+
1041
.woopay-save-new-user-container {
42+
.save-details {
43+
.wc-block-components-text-input input:-webkit-autofill {
44+
padding: 1.5em 0.5em 1.5em 0.5em;
45+
}
46+
}
47+
48+
&.wc-version-greater-than-91 {
49+
@media ( min-width: 601px ),
50+
( min-width: 566px ) and ( max-width: 568px ) {
51+
.save-details {
52+
margin-bottom: 48px;
53+
}
54+
}
55+
}
56+
1157
.save-details-header {
1258
display: flex;
1359
align-items: flex-start;
@@ -41,7 +87,7 @@
4187
text-indent: 0;
4288
}
4389

44-
input {
90+
input:not( .without-margin-right ) {
4591
margin-right: $gap-small;
4692
}
4793

client/components/woopay/save-user/test/checkout-page-save-user.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ describe( 'CheckoutPageSaveUser', () => {
8383
( setting ) => setting === 'forceNetworkSavedCards'
8484
);
8585

86+
window.wcSettings = {
87+
wcVersion: '9.1.2',
88+
storePages: {
89+
checkout: {
90+
permalink: 'http://localhost/',
91+
},
92+
},
93+
};
94+
8695
window.wcpaySettings = {
8796
accountStatus: {
8897
country: 'US',

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"@woocommerce/explat": "2.3.0",
8383
"@woocommerce/number": "2.4.0",
8484
"canvas-confetti": "1.9.2",
85+
"compare-versions": "6.1.1",
8586
"debug": "4.1.1",
8687
"intl-tel-input": "17.0.15",
8788
"lodash": "4.17.21"

0 commit comments

Comments
 (0)