Skip to content

Commit 89208fc

Browse files
authored
fix(modal-checkout): prevent session reload after new customer account (#4310)
* fix(modal-checkout): prevent session reload after new customer account * style: apply newspack-ui notice styles to all nested woo notices * fix: no border on notices nested in notices
1 parent 6e3c5f8 commit 89208fc

File tree

3 files changed

+66
-39
lines changed

3 files changed

+66
-39
lines changed

includes/data-events/class-woo-user-registration.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public static function init() {
3737

3838
// created a user?
3939
add_action( 'woocommerce_created_customer', [ __CLASS__, 'created_customer' ], 1 );
40+
41+
// checkout order processed?
42+
add_action( 'woocommerce_checkout_order_processed', [ __CLASS__, 'checkout_order_processed' ] );
4043
}
4144

4245
/**
@@ -99,6 +102,19 @@ public static function created_customer( $user_id ) {
99102
*/
100103
\do_action( 'newspack_registered_reader_via_woo', $user->user_email, $user_id, self::$metadata );
101104
}
105+
106+
/**
107+
* After a checkout order is processed, prevent the modal checkout from reloading.
108+
*
109+
* @param int $order_id The ID of the processed order.
110+
* @return void
111+
*/
112+
public static function checkout_order_processed( $order_id ) {
113+
// Prevent the modal checkout from reloading after the user is created.
114+
if ( method_exists( 'Newspack_Blocks\Modal_Checkout', 'is_modal_checkout' ) && \Newspack_Blocks\Modal_Checkout::is_modal_checkout() ) {
115+
\WC()->session->set( 'reload_checkout', null );
116+
}
117+
}
102118
}
103119

104120
Woo_User_Registration::init();

src/newspack-ui/scss/elements/woocommerce/_my-account.scss

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,10 @@
33
*/
44

55
@use "../forms";
6-
@use "../notices";
76
@use "../typography";
87
@use "../../variables/breakpoints";
98

109
.woocommerce-account.newspack-my-account.newspack-ui {
11-
.woocommerce-notices-wrapper:not(:empty) {
12-
margin-bottom: var(--newspack-ui-spacer-6);
13-
14-
> *:first-child {
15-
margin-top: 0;
16-
}
17-
}
18-
.newspack-wc-message,
19-
.woocommerce-message,
20-
.woocommerce-info,
21-
.woocommerce-error {
22-
@extend .newspack-ui__notice;
23-
display: block;
24-
list-style: none;
25-
margin: var(--newspack-ui-spacer-3) 0;
26-
27-
> p:first-child {
28-
margin-top: 0;
29-
padding-top: 0;
30-
}
31-
32-
> p:last-child {
33-
margin-bottom: 0;
34-
padding-bottom: 0;
35-
}
36-
}
37-
.newspack-wc-message,
38-
.woocommerce-message {
39-
@extend .newspack-ui__notice--success;
40-
}
41-
.woocommerce-info {
42-
@extend .newspack-ui__notice--warning;
43-
}
44-
.newspack-wc-message--error,
45-
.woocommerce-error {
46-
@extend .newspack-ui__notice--error;
47-
}
4810
p.woocommerce-form-row {
4911
margin: var(--newspack-ui-spacer-3) 0;
5012
}
@@ -190,7 +152,8 @@
190152
address {
191153
font-style: normal;
192154
}
193-
#registration-link_field .regenerate-link { // stylelint-disable-line selector-id-pattern
155+
/* stylelint-disable-next-line selector-id-pattern */
156+
#registration-link_field .regenerate-link {
194157
margin-left: var(--newspack-ui-spacer-3);
195158
}
196159
}

src/newspack-ui/scss/elements/woocommerce/_overrides.scss

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/** Some general overrides for WooCommerce styles. */
2+
3+
@use "../notices";
4+
25
.newspack-ui {
36
label .optional {
47
color: var(--newspack-ui-color-neutral-60);
@@ -26,6 +29,51 @@
2629
font-weight: normal;
2730
}
2831
}
32+
.woocommerce-notices-wrapper:not(:empty) {
33+
margin-bottom: var(--newspack-ui-spacer-6);
34+
35+
> *:first-child {
36+
margin-top: 0;
37+
}
38+
}
39+
.newspack-wc-message,
40+
.woocommerce-message,
41+
.woocommerce-info,
42+
.woocommerce-error {
43+
@extend .newspack-ui__notice;
44+
display: block;
45+
list-style: none;
46+
margin: var(--newspack-ui-spacer-3) 0;
47+
48+
> p:first-child {
49+
margin-top: 0;
50+
padding-top: 0;
51+
}
52+
53+
> p:last-child {
54+
margin-bottom: 0;
55+
padding-bottom: 0;
56+
}
57+
}
58+
.newspack-wc-message,
59+
.woocommerce-message {
60+
@extend .newspack-ui__notice--success;
61+
}
62+
.woocommerce-info {
63+
@extend .newspack-ui__notice--warning;
64+
}
65+
.newspack-wc-message--error,
66+
.woocommerce-error {
67+
@extend .newspack-ui__notice--error;
68+
}
69+
.woocommerce-NoticeGroup {
70+
.newspack-wc-message,
71+
.woocommerce-message,
72+
.woocommerce-info,
73+
.woocommerce-error {
74+
border: none !important;
75+
}
76+
}
2977
}
3078

3179
/** See #3292. */

0 commit comments

Comments
 (0)