Skip to content

Commit 0f25185

Browse files
committed
fix: prevent classic checkout CSS from loading on blocks checkout
- Added is_block_checkout_page() method to base WCMoneiPaymentGateway class - Added check in WCGatewayMoneiCC and WCGatewayMoneiAppleGoogle to skip classic CSS enqueuing on blocks checkout - Uses WC_Blocks_Utils::has_block_in_page() to detect blocks checkout at script enqueue time - Prevents CSS conflicts between classic and blocks checkout
1 parent ac52d42 commit 0f25185

File tree

5 files changed

+61
-4
lines changed

5 files changed

+61
-4
lines changed

assets/css/monei-blocks-checkout.css

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
font-size: 1em;
1111
height: 3.125em;
1212
line-height: 1;
13-
margin: 0 0 0.75em 0;
1413
min-height: 0;
1514
padding: 0;
1615
width: 100%;
@@ -68,9 +67,7 @@
6867

6968
/* Label Container */
7069
.monei-label-container {
71-
display: flex;
72-
align-items: center;
73-
gap: 1em;
70+
display: block;
7471
}
7572

7673
.monei-text {

src/Gateways/Abstracts/WCMoneiPaymentGateway.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use WC_Admin_Settings;
1313
use WC_Monei_Logger;
1414
use WC_Payment_Gateway;
15+
use WC_Blocks_Utils;
1516

1617
if ( ! defined( 'ABSPATH' ) ) {
1718
exit;
@@ -362,6 +363,30 @@ public function isBlockCheckout() {
362363
return ( isset( $_POST['monei_is_block_checkout'] ) ) ? wc_clean( wp_unslash( $_POST['monei_is_block_checkout'] ) ) === 'yes' : false; // WPCS: CSRF ok.
363364
}
364365

366+
/**
367+
* Check if the checkout page is using WooCommerce Blocks.
368+
* Used for script enqueuing to differentiate between classic and blocks checkout.
369+
*
370+
* @return bool
371+
*/
372+
public function is_block_checkout_page() {
373+
if ( ! is_checkout() ) {
374+
return false;
375+
}
376+
if ( ! class_exists( 'WC_Blocks_Utils' ) ) {
377+
return false;
378+
}
379+
// Check if the checkout block is present
380+
$has_block = WC_Blocks_Utils::has_block_in_page( wc_get_page_id( 'checkout' ), 'woocommerce/checkout' );
381+
382+
// Additional check: see if the traditional checkout shortcode is present
383+
$checkout_page = get_post( wc_get_page_id( 'checkout' ) );
384+
$has_shortcode = $checkout_page ? has_shortcode( $checkout_page->post_content, 'woocommerce_checkout' ) : false;
385+
386+
// If the block is present and the shortcode is not, we can be more confident it's a block checkout
387+
return $has_block && ! $has_shortcode;
388+
}
389+
365390
/**
366391
* Frontend MONEI generated token.
367392
*

src/Gateways/Abstracts/WCMoneiPaymentGatewayComponent.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use WC_Order;
1111
use WC_Payment_Tokens;
1212
use WC_Monei_Logger;
13+
use WC_Blocks_Utils;
1314

1415
if ( ! defined( 'ABSPATH' ) ) {
1516
exit;
@@ -292,6 +293,30 @@ public function isBlockCheckout() {
292293
return ( isset( $_POST['monei_is_block_checkout'] ) ) ? wc_clean( wp_unslash( $_POST['monei_is_block_checkout'] ) ) === 'yes' : false; // WPCS: CSRF ok.
293294
}
294295

296+
/**
297+
* Check if the checkout page is using WooCommerce Blocks.
298+
* Used for script enqueuing to differentiate between classic and blocks checkout.
299+
*
300+
* @return bool
301+
*/
302+
public function is_block_checkout_page() {
303+
if ( ! is_checkout() ) {
304+
return false;
305+
}
306+
if ( ! class_exists( 'WC_Blocks_Utils' ) ) {
307+
return false;
308+
}
309+
// Check if the checkout block is present
310+
$has_block = WC_Blocks_Utils::has_block_in_page( wc_get_page_id( 'checkout' ), 'woocommerce/checkout' );
311+
312+
// Additional check: see if the traditional checkout shortcode is present
313+
$checkout_page = get_post( wc_get_page_id( 'checkout' ) );
314+
$has_shortcode = $checkout_page ? has_shortcode( $checkout_page->post_content, 'woocommerce_checkout' ) : false;
315+
316+
// If the block is present and the shortcode is not, we can be more confident it's a block checkout
317+
return $has_block && ! $has_shortcode;
318+
}
319+
295320
/**
296321
* Frontend MONEI cardholderName.
297322
*

src/Gateways/PaymentMethods/WCGatewayMoneiAppleGoogle.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ public function monei_scripts() {
170170
return;
171171
}
172172

173+
// Don't load classic CSS on blocks checkout
174+
if ( $this->is_block_checkout_page() ) {
175+
return;
176+
}
177+
173178
// Register and enqueue classic checkout CSS
174179
wp_register_style(
175180
'monei-classic-checkout',

src/Gateways/PaymentMethods/WCGatewayMoneiCC.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,11 @@ public function monei_scripts() {
420420
return;
421421
}
422422

423+
// Don't load classic CSS on blocks checkout
424+
if ( $this->is_block_checkout_page() ) {
425+
return;
426+
}
427+
423428
// Register and enqueue classic checkout CSS
424429
wp_register_style(
425430
'monei-classic-checkout',

0 commit comments

Comments
 (0)