Checkout i2: support odd classes when transforming from Checkout i1 to Checkout i2 (https://github.com/woocommerce/woocommerce-blocks/pull/4866)

* support odd classes for Checkout

* support classNames at start of string

* keep classNames and aligment on frontend
This commit is contained in:
Seghir Nadir 2021-09-29 11:54:50 +01:00 committed by GitHub
parent cd5e31d9ba
commit 77e3da81b2
1 changed files with 6 additions and 5 deletions

View File

@ -77,13 +77,14 @@ class Checkout extends AbstractBlock {
wp_dequeue_style( 'select2' );
// If the content is empty, we may have transformed from an older checkout block. Insert the default list of blocks.
$is_empty = strstr( $content, '<div class="wp-block-woocommerce-checkout is-loading"></div>' );
$regex_for_empty_block = '/<div class="[a-zA-Z0-9_\- ]*wp-block-woocommerce-checkout[a-zA-Z0-9_\- ]*"><\/div>/mi';
$is_empty = preg_match( $regex_for_empty_block, $content );
if ( $is_empty ) {
$content = '<div class="wp-block-woocommerce-checkout is-loading">
<div data-block-name="woocommerce/checkout-fields-block" class="wp-block-woocommerce-checkout-fields-block"></div>
<div data-block-name="woocommerce/checkout-totals-block" class="wp-block-woocommerce-checkout-totals-block"></div>
</div>';
$inner_blocks_html = '<div data-block-name="woocommerce/checkout-fields-block" class="wp-block-woocommerce-checkout-fields-block"></div><div data-block-name="woocommerce/checkout-totals-block" class="wp-block-woocommerce-checkout-totals-block"></div>';
$content = str_replace( '</div>', $inner_blocks_html . '</div>', $content );
}
return $this->inject_html_data_attributes( $content, $attributes );