Accordion
1 year ago
AddToCartWithOptions
1 week ago
OrderConfirmation
2 months ago
ProductCollection
3 weeks ago
Reviews
2 months ago
AbstractBlock.php
4 weeks ago
AbstractDynamicBlock.php
2 years ago
AbstractInnerBlock.php
1 year ago
AbstractProductGrid.php
3 months ago
ActiveFilters.php
2 years ago
AddToCartForm.php
4 weeks ago
AddToWishlistButton.php
4 weeks ago
AllProducts.php
2 years ago
AllReviews.php
2 years ago
AtomicBlock.php
2 years ago
AttributeFilter.php
1 year ago
Breadcrumbs.php
1 year ago
Cart.php
2 months ago
CartAcceptedPaymentMethodsBlock.php
2 years ago
CartCrossSellsBlock.php
2 years ago
CartCrossSellsProductsBlock.php
2 years ago
CartExpressPaymentBlock.php
1 year ago
CartItemsBlock.php
2 years ago
CartLineItemsBlock.php
2 years ago
CartLink.php
2 months ago
CartOrderSummaryBlock.php
2 years ago
CartOrderSummaryCouponFormBlock.php
2 years ago
CartOrderSummaryDiscountBlock.php
2 years ago
CartOrderSummaryFeeBlock.php
2 years ago
CartOrderSummaryHeadingBlock.php
2 years ago
CartOrderSummaryShippingBlock.php
2 years ago
CartOrderSummarySubtotalBlock.php
2 years ago
CartOrderSummaryTaxesBlock.php
2 years ago
CartOrderSummaryTotalsBlock.php
2 years ago
CartTotalsBlock.php
2 years ago
CatalogSorting.php
4 weeks ago
CategoryDescription.php
2 months ago
CategoryTitle.php
2 months ago
Checkout.php
2 months ago
CheckoutActionsBlock.php
1 year ago
CheckoutAdditionalInformationBlock.php
2 years ago
CheckoutBillingAddressBlock.php
2 years ago
CheckoutContactInformationBlock.php
2 years ago
CheckoutExpressPaymentBlock.php
9 months ago
CheckoutFieldsBlock.php
2 years ago
CheckoutOrderNoteBlock.php
2 years ago
CheckoutOrderSummaryBlock.php
2 years ago
CheckoutOrderSummaryCartItemsBlock.php
2 years ago
CheckoutOrderSummaryCouponFormBlock.php
2 years ago
CheckoutOrderSummaryDiscountBlock.php
2 years ago
CheckoutOrderSummaryFeeBlock.php
2 years ago
CheckoutOrderSummaryShippingBlock.php
2 years ago
CheckoutOrderSummarySubtotalBlock.php
2 years ago
CheckoutOrderSummaryTaxesBlock.php
2 years ago
CheckoutOrderSummaryTotalsBlock.php
2 years ago
CheckoutPaymentBlock.php
2 years ago
CheckoutPickupOptionsBlock.php
2 years ago
CheckoutShippingAddressBlock.php
2 years ago
CheckoutShippingMethodBlock.php
2 years ago
CheckoutShippingMethodsBlock.php
2 years ago
CheckoutTermsBlock.php
2 years ago
CheckoutTotalsBlock.php
2 years ago
ClassicShortcode.php
1 year ago
ClassicTemplate.php
4 months ago
ComingSoon.php
1 year ago
CouponCode.php
2 months ago
CustomerAccount.php
3 months ago
Dropdown.php
4 weeks ago
EmailContent.php
5 months ago
EmptyCartBlock.php
2 years ago
EmptyMiniCartContentsBlock.php
11 months ago
EnableBlockJsonAssetsTrait.php
1 year ago
FeaturedCategory.php
7 months ago
FeaturedItem.php
7 months ago
FeaturedProduct.php
7 months ago
FilledCartBlock.php
2 years ago
FilledMiniCartContentsBlock.php
4 months ago
FilterWrapper.php
2 years ago
HandpickedProducts.php
1 year ago
MiniCart.php
4 weeks ago
MiniCartCartButtonBlock.php
11 months ago
MiniCartCheckoutButtonBlock.php
11 months ago
MiniCartContents.php
3 months ago
MiniCartFooterBlock.php
4 weeks ago
MiniCartItemsBlock.php
11 months ago
MiniCartProductsTableBlock.php
4 weeks ago
MiniCartShoppingButtonBlock.php
9 months ago
MiniCartTitleBlock.php
11 months ago
MiniCartTitleItemsCounterBlock.php
11 months ago
MiniCartTitleLabelBlock.php
11 months ago
NextPreviousButtons.php
5 months ago
PageContentWrapper.php
2 years ago
PaymentMethodIcons.php
11 months ago
PriceFilter.php
1 year ago
ProceedToCheckoutBlock.php
2 years ago
ProductAverageRating.php
1 year ago
ProductBestSellers.php
2 years ago
ProductButton.php
2 months ago
ProductCategories.php
4 weeks ago
ProductCategory.php
2 years ago
ProductDescription.php
9 months ago
ProductDetails.php
5 months ago
ProductFilterActive.php
4 weeks ago
ProductFilterAttribute.php
4 weeks ago
ProductFilterCheckboxList.php
4 weeks ago
ProductFilterChips.php
4 weeks ago
ProductFilterClearButton.php
4 weeks ago
ProductFilterPrice.php
4 weeks ago
ProductFilterPriceSlider.php
4 weeks ago
ProductFilterRating.php
4 weeks ago
ProductFilterRemovableChips.php
4 weeks ago
ProductFilterStatus.php
4 weeks ago
ProductFilterTaxonomy.php
4 weeks ago
ProductFilters.php
3 weeks ago
ProductGallery.php
4 weeks ago
ProductGalleryLargeImage.php
4 weeks ago
ProductGalleryThumbnails.php
4 weeks ago
ProductImage.php
4 weeks ago
ProductImageGallery.php
7 months ago
ProductMeta.php
1 year ago
ProductNew.php
2 years ago
ProductOnSale.php
2 years ago
ProductPrice.php
2 months ago
ProductQuery.php
4 weeks ago
ProductRating.php
1 year ago
ProductRatingCounter.php
1 year ago
ProductRatingStars.php
1 year ago
ProductResultsCount.php
2 months ago
ProductSKU.php
2 months ago
ProductSaleBadge.php
1 year ago
ProductSearch.php
10 months ago
ProductSpecifications.php
2 months ago
ProductStockIndicator.php
2 months ago
ProductSummary.php
7 months ago
ProductTag.php
2 years ago
ProductTemplate.php
2 months ago
ProductTitle.php
1 year ago
ProductTopRated.php
2 years ago
ProductsByAttribute.php
2 years ago
RatingFilter.php
2 years ago
RelatedProducts.php
3 months ago
ReviewsByCategory.php
2 years ago
ReviewsByProduct.php
2 years ago
SavedForLater.php
4 weeks ago
SingleProduct.php
2 months ago
StockFilter.php
2 years ago
StoreNotices.php
1 year ago
Wishlist.php
4 weeks ago
CheckoutOrderSummaryBlock.php
81 lines
| 1 | <?php |
| 2 | namespace Automattic\WooCommerce\Blocks\BlockTypes; |
| 3 | |
| 4 | /** |
| 5 | * CheckoutOrderSummaryBlock class. |
| 6 | */ |
| 7 | class CheckoutOrderSummaryBlock extends AbstractInnerBlock { |
| 8 | /** |
| 9 | * Block name. |
| 10 | * |
| 11 | * @var string |
| 12 | */ |
| 13 | protected $block_name = 'checkout-order-summary-block'; |
| 14 | |
| 15 | /** |
| 16 | * Get the contents of the given inner block. |
| 17 | * |
| 18 | * @param string $block_name Name of the order summary inner block. |
| 19 | * @param string $content The content to search. |
| 20 | * @return array|bool |
| 21 | */ |
| 22 | private function get_inner_block_content( $block_name, $content ) { |
| 23 | if ( preg_match( $this->inner_block_regex( $block_name ), $content, $matches ) ) { |
| 24 | return $matches[0]; |
| 25 | } |
| 26 | return false; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Get the regex that will return an inner block. |
| 31 | * |
| 32 | * @param string $block_name Name of the order summary inner block. |
| 33 | * @return string Regex pattern. |
| 34 | */ |
| 35 | private function inner_block_regex( $block_name ) { |
| 36 | return '/<div data-block-name="woocommerce\/checkout-order-summary-' . $block_name . '-block"(.+?)>(.*?)<\/div>/si'; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Render the Checkout Order Summary block. |
| 41 | * |
| 42 | * @param array $attributes Block attributes. |
| 43 | * @param string $content Block content. |
| 44 | * @param object $block Block object. |
| 45 | * @return string Rendered block. |
| 46 | */ |
| 47 | protected function render( $attributes, $content, $block ) { |
| 48 | // The order-summary-totals block was introduced as a new parent block for the totals |
| 49 | // (subtotal, discount, fees, shipping and taxes) blocks. |
| 50 | $regex_for_checkout_order_summary_totals = '/<div data-block-name="woocommerce\/checkout-order-summary-totals-block"(.+?)>/'; |
| 51 | $order_summary_totals_content = '<div data-block-name="woocommerce/checkout-order-summary-totals-block" class="wp-block-woocommerce-checkout-order-summary-totals-block">'; |
| 52 | |
| 53 | // We want to move these blocks inside a parent 'totals' block. |
| 54 | $totals_inner_blocks = array( 'subtotal', 'discount', 'fee', 'shipping', 'taxes' ); |
| 55 | |
| 56 | if ( preg_match( $regex_for_checkout_order_summary_totals, $content ) ) { |
| 57 | return $content; |
| 58 | } |
| 59 | |
| 60 | foreach ( $totals_inner_blocks as $key => $block_name ) { |
| 61 | $inner_block_content = $this->get_inner_block_content( $block_name, $content ); |
| 62 | |
| 63 | if ( $inner_block_content ) { |
| 64 | $order_summary_totals_content .= "\n" . $inner_block_content; |
| 65 | |
| 66 | // The last block is replaced with the totals block. |
| 67 | if ( count( $totals_inner_blocks ) - 1 === $key ) { |
| 68 | $order_summary_totals_content .= '</div>'; |
| 69 | $content = preg_replace( $this->inner_block_regex( $block_name ), $order_summary_totals_content, $content ); |
| 70 | } else { |
| 71 | // Otherwise, remove the block. |
| 72 | $content = preg_replace( $this->inner_block_regex( $block_name ), '', $content ); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // Remove empty lines. |
| 78 | return preg_replace( '/\n\n( *?)/i', '', $content ); |
| 79 | } |
| 80 | } |
| 81 |