From 45f710882a913eab8f24e7f6a58e180d9e87131a Mon Sep 17 00:00:00 2001 From: Saad Tarhi Date: Mon, 27 Mar 2023 07:14:39 +0000 Subject: [PATCH 1/2] Fix duplicate "Shipping method" Block on the front-end - Issue: When local pickup is enabled and the shipping method's description is edited, the "Shipping method" is duplicated on the front-end - Solution: The previous regex didn't match some special characters such as ".", "!", etc. Because of that, it considers the Local Pickup toggle template to be missing and duplicate it. --- src/BlockTypes/Checkout.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BlockTypes/Checkout.php b/src/BlockTypes/Checkout.php index 75b15c45abc..d951c363497 100644 --- a/src/BlockTypes/Checkout.php +++ b/src/BlockTypes/Checkout.php @@ -155,11 +155,11 @@ protected function render( $attributes, $content, $block ) { * Add the Local Pickup toggle to checkouts missing this forced template. */ $local_pickup_inner_blocks = '
' . PHP_EOL . PHP_EOL . '
' . PHP_EOL . PHP_EOL . '$0'; - $has_local_pickup_regex = '//mi'; + $has_local_pickup_regex = '/]*?>/mi'; $has_local_pickup = preg_match( $has_local_pickup_regex, $content ); if ( ! $has_local_pickup ) { - $shipping_address_block_regex = '/<\/div>/mi'; + $shipping_address_block_regex = '/]*?><\/div>/mi'; $content = preg_replace( $shipping_address_block_regex, $local_pickup_inner_blocks, $content ); } From 27c12a853ff1b4bb7b6e0b7edd56ed880ecfc0c5 Mon Sep 17 00:00:00 2001 From: Saad Tarhi Date: Mon, 27 Mar 2023 07:21:19 +0000 Subject: [PATCH 2/2] Fix the regex looking for block templates The previous regex didn't account for some special characters that the user can use for a block's title or description, such as ".", "!", etc. As a result, the Block's template will be considered missing. --- src/BlockTypes/Cart.php | 6 +++--- src/BlockTypes/Checkout.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/BlockTypes/Cart.php b/src/BlockTypes/Cart.php index 1888272f32b..d9baf83f9f5 100644 --- a/src/BlockTypes/Cart.php +++ b/src/BlockTypes/Cart.php @@ -98,7 +98,7 @@ protected function render( $attributes, $content, $block ) { * The blocks used for testing should be always available in the block (not removable by the user). */ - $regex_for_filled_cart_block = '//mi'; + $regex_for_filled_cart_block = '/]*?>/mi'; // Filled Cart block was added in i2, so we search for it to see if we have a Cart i1 template. $has_i1_template = ! preg_match( $regex_for_filled_cart_block, $content ); @@ -140,8 +140,8 @@ protected function render( $attributes, $content, $block ) {
'; // Order summary subtotal block was added in i3, so we search for it to see if we have a Cart i2 template. - $regex_for_order_summary_subtotal = '//mi'; - $regex_for_order_summary = '//mi'; + $regex_for_order_summary_subtotal = '/]*?>/mi'; + $regex_for_order_summary = '/]*?>/mi'; $has_i2_template = ! preg_match( $regex_for_order_summary_subtotal, $content ); if ( $has_i2_template ) { diff --git a/src/BlockTypes/Checkout.php b/src/BlockTypes/Checkout.php index d951c363497..107d66b93cc 100644 --- a/src/BlockTypes/Checkout.php +++ b/src/BlockTypes/Checkout.php @@ -143,8 +143,8 @@ protected function render( $attributes, $content, $block ) {
'; // Order summary subtotal block was added in i3, so we search for it to see if we have a Checkout i2 template. - $regex_for_order_summary_subtotal = '//mi'; - $regex_for_order_summary = '//mi'; + $regex_for_order_summary_subtotal = '/]*?>/mi'; + $regex_for_order_summary = '/]*?>/mi'; $has_i2_template = ! preg_match( $regex_for_order_summary_subtotal, $content ); if ( $has_i2_template ) {