at path:
ROOT
/
wp-content
/
plugins
/
woocommerce
/
src
/
Blocks
/
BlockTypes
/
Cart.php
run:
R
W
Run
Accordion
DIR
2026-04-15 05:42:46
R
W
Run
AddToCartWithOptions
DIR
2026-04-15 05:42:46
R
W
Run
OrderConfirmation
DIR
2026-04-15 05:42:46
R
W
Run
ProductCollection
DIR
2026-04-15 05:42:46
R
W
Run
Reviews
DIR
2026-04-15 05:42:46
R
W
Run
AbstractBlock.php
15.6 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
AbstractDynamicBlock.php
1.85 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
AbstractInnerBlock.php
1.74 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
AbstractProductGrid.php
22.14 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ActiveFilters.php
226 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
AddToCartForm.php
9.28 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
AllProducts.php
1.99 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
AllReviews.php
1.29 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
AtomicBlock.php
910 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
AttributeFilter.php
1.5 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
Breadcrumbs.php
2.7 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
Cart.php
13.07 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CartAcceptedPaymentMethodsBlock.php
288 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CartCrossSellsBlock.php
251 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CartCrossSellsProductsBlock.php
276 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CartExpressPaymentBlock.php
507 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CartItemsBlock.php
235 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CartLineItemsBlock.php
248 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CartLink.php
1.55 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CartOrderSummaryBlock.php
2.67 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CartOrderSummaryCouponFormBlock.php
289 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CartOrderSummaryDiscountBlock.php
282 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CartOrderSummaryFeeBlock.php
267 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CartOrderSummaryHeadingBlock.php
279 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CartOrderSummaryShippingBlock.php
282 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CartOrderSummarySubtotalBlock.php
282 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CartOrderSummaryTaxesBlock.php
273 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CartOrderSummaryTotalsBlock.php
276 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CartTotalsBlock.php
238 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CatalogSorting.php
1.48 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CategoryDescription.php
1.7 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CategoryTitle.php
2.36 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
Checkout.php
26.69 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutActionsBlock.php
1003 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutAdditionalInformationBlock.php
296 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutBillingAddressBlock.php
275 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutContactInformationBlock.php
287 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutExpressPaymentBlock.php
4.13 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutFieldsBlock.php
250 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutOrderNoteBlock.php
260 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutOrderSummaryBlock.php
2.74 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutOrderSummaryCartItemsBlock.php
298 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutOrderSummaryCouponFormBlock.php
301 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutOrderSummaryDiscountBlock.php
294 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutOrderSummaryFeeBlock.php
279 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutOrderSummaryShippingBlock.php
294 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutOrderSummarySubtotalBlock.php
294 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutOrderSummaryTaxesBlock.php
285 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutOrderSummaryTotalsBlock.php
288 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutPaymentBlock.php
253 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutPickupOptionsBlock.php
272 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutShippingAddressBlock.php
278 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutShippingMethodBlock.php
275 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutShippingMethodsBlock.php
278 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutTermsBlock.php
247 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CheckoutTotalsBlock.php
250 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ClassicShortcode.php
3.03 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ClassicTemplate.php
12.62 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ComingSoon.php
3.58 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CouponCode.php
7.97 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
CustomerAccount.php
14.44 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
EmailContent.php
3.23 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
EmptyCartBlock.php
235 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
EmptyMiniCartContentsBlock.php
1.79 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
EnableBlockJsonAssetsTrait.php
775 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
FeaturedCategory.php
2.72 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
FeaturedItem.php
13.88 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
FeaturedProduct.php
3.33 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
FilledCartBlock.php
238 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
FilledMiniCartContentsBlock.php
3.45 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
FilterWrapper.php
376 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
HandpickedProducts.php
1.89 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
MiniCart.php
35.07 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
MiniCartCartButtonBlock.php
2.24 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
MiniCartCheckoutButtonBlock.php
1.97 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
MiniCartContents.php
6.62 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
MiniCartFooterBlock.php
5.63 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
MiniCartItemsBlock.php
1.51 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
MiniCartProductsTableBlock.php
12.8 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
MiniCartShoppingButtonBlock.php
2.02 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
MiniCartTitleBlock.php
1.5 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
MiniCartTitleItemsCounterBlock.php
2.28 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
MiniCartTitleLabelBlock.php
1.55 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
NextPreviousButtons.php
3.36 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
PageContentWrapper.php
705 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
PaymentMethodIcons.php
6.17 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
PriceFilter.php
1.25 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProceedToCheckoutBlock.php
783 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductAverageRating.php
2.08 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductBestSellers.php
444 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductButton.php
12.47 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductCategories.php
12.75 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductCategory.php
733 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductDescription.php
2.48 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductDetails.php
16.03 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductFilterActive.php
2.51 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductFilterAttribute.php
12.74 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductFilterCheckboxList.php
5.65 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductFilterChips.php
4.69 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductFilterClearButton.php
1.45 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductFilterPrice.php
6.97 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductFilterPriceSlider.php
5.36 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductFilterRating.php
7.1 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductFilterRemovableChips.php
3.79 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductFilterStatus.php
6.62 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductFilterTaxonomy.php
18.47 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductFilters.php
9.93 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductGallery.php
6.49 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductGalleryLargeImage.php
8 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductGalleryThumbnails.php
4.18 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductImage.php
8.76 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductImageGallery.php
3.55 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductMeta.php
1009 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductNew.php
448 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductOnSale.php
761 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductPrice.php
4.72 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductQuery.php
27.8 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductRating.php
6.09 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductRatingCounter.php
5.46 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductRatingStars.php
3.76 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductResultsCount.php
1.77 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductSKU.php
3.31 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductSaleBadge.php
2.69 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductSearch.php
3.49 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductSpecifications.php
5.68 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductStockIndicator.php
5.96 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductSummary.php
7.34 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductTag.php
2.23 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductTemplate.php
5.79 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductTitle.php
619 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductTopRated.php
424 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ProductsByAttribute.php
2.05 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
RatingFilter.php
704 By
2026-04-15 05:42:46
R
W
Run
Delete
Rename
RelatedProducts.php
5.17 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ReviewsByCategory.php
1.31 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
ReviewsByProduct.php
1.3 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
SingleProduct.php
7.14 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
StockFilter.php
1.34 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
StoreNotices.php
1.7 KB
2026-04-15 05:42:46
R
W
Run
Delete
Rename
error_log
up
📄
Cart.php
Save
<?php namespace Automattic\WooCommerce\Blocks\BlockTypes; use Automattic\WooCommerce\Blocks\Utils\CartCheckoutUtils; /** * Cart class. * * @internal */ class Cart extends AbstractBlock { /** * Block name. * * @var string */ protected $block_name = 'cart'; /** * Chunks build folder. * * @var string */ protected $chunks_folder = 'cart-blocks'; /** * Initialize this block type. * * - Hook into WP lifecycle. * - Register the block with WordPress. */ protected function initialize() { parent::initialize(); add_action( 'wp_loaded', array( $this, 'register_patterns' ) ); } /** * Dequeues the scripts added by WC Core to the Cart page. * * @return void */ public function dequeue_woocommerce_core_scripts() { wp_dequeue_script( 'wc-cart' ); wp_dequeue_script( 'wc-password-strength-meter' ); wp_dequeue_script( 'selectWoo' ); wp_dequeue_style( 'select2' ); } /** * Register block pattern for Empty Cart Message to make it translatable. */ public function register_patterns() { $shop_permalink = wc_get_page_permalink( 'shop' ); register_block_pattern( 'woocommerce/cart-heading', array( 'title' => '', 'inserter' => false, 'content' => '<!-- wp:heading {"align":"wide", "level":1} --><h1 class="wp-block-heading alignwide">' . esc_html__( 'Cart', 'woocommerce' ) . '</h1><!-- /wp:heading -->', ) ); register_block_pattern( 'woocommerce/cart-cross-sells-message', array( 'title' => '', 'inserter' => false, 'content' => '<!-- wp:heading {"fontSize":"large"} --><h2 class="wp-block-heading has-large-font-size">' . esc_html__( 'You may be interested in…', 'woocommerce' ) . '</h2><!-- /wp:heading -->', ) ); register_block_pattern( 'woocommerce/cart-empty-message', array( 'title' => '', 'inserter' => false, 'content' => ' <!-- wp:heading {"textAlign":"center","className":"with-empty-cart-icon wc-block-cart__empty-cart__title"} --><h2 class="wp-block-heading has-text-align-center with-empty-cart-icon wc-block-cart__empty-cart__title">' . esc_html__( 'Your cart is currently empty!', 'woocommerce' ) . '</h2><!-- /wp:heading --> <!-- wp:paragraph {"align":"center"} --><p class="has-text-align-center"><a href="' . esc_attr( esc_url( $shop_permalink ) ) . '">' . esc_html__( 'Browse store', 'woocommerce' ) . '</a></p><!-- /wp:paragraph --> ', ) ); register_block_pattern( 'woocommerce/cart-new-in-store-message', array( 'title' => '', 'inserter' => false, 'content' => '<!-- wp:heading {"textAlign":"center"} --><h2 class="wp-block-heading has-text-align-center">' . esc_html__( 'New in store', 'woocommerce' ) . '</h2><!-- /wp:heading -->', ) ); } /** * Get the editor script handle for this block type. * * @param string $key Data to get, or default to everything. * @return array|string; */ protected function get_block_type_editor_script( $key = null ) { $script = [ 'handle' => 'wc-' . $this->block_name . '-block', 'path' => $this->asset_api->get_block_asset_build_path( $this->block_name ), 'dependencies' => [ 'wc-blocks' ], ]; return $key ? $script[ $key ] : $script; } /** * Get the frontend script handle for this block type. * * @see $this->register_block_type() * @param string $key Data to get, or default to everything. * @return array|string */ protected function get_block_type_script( $key = null ) { $script = [ 'handle' => 'wc-' . $this->block_name . '-block-frontend', 'path' => $this->asset_api->get_block_asset_build_path( $this->block_name . '-frontend' ), 'dependencies' => [], ]; return $key ? $script[ $key ] : $script; } /** * Get the frontend style handle for this block type. * * @return string[] */ protected function get_block_type_style() { return array_merge( parent::get_block_type_style(), [ 'wc-blocks-packages-style' ] ); } /** * Enqueue frontend assets for this block, just in time for rendering. * * @param array $attributes Any attributes that currently are available from the block. * @param string $content The block content. * @param WP_Block $block The block object. */ protected function enqueue_assets( array $attributes, $content, $block ) { /** * Fires before cart block scripts are enqueued. * * @since 2.6.0 */ do_action( 'woocommerce_blocks_enqueue_cart_block_scripts_before' ); parent::enqueue_assets( $attributes, $content, $block ); /** * Fires after cart block scripts are enqueued. * * @since 2.6.0 */ do_action( 'woocommerce_blocks_enqueue_cart_block_scripts_after' ); } /** * Append frontend scripts when rendering the Cart block. * * @param array $attributes Block attributes. * @param string $content Block content. * @param WP_Block $block Block instance. * @return string Rendered block type output. */ protected function render( $attributes, $content, $block ) { // Dequeue the core scripts when rendering this block. add_action( 'wp_enqueue_scripts', array( $this, 'dequeue_woocommerce_core_scripts' ), 20 ); /** * We need to check if $content has any templates from prior iterations of the block, in order to update to the latest iteration. * We test the iteration version by searching for new blocks brought in by it. * The blocks used for testing should be always available in the block (not removable by the user). */ $regex_for_filled_cart_block = '/<div[^<]*?data-block-name="woocommerce\/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 ); if ( $has_i1_template ) { /** * This fallback structure needs to match the defaultTemplate variables defined in the block's edit.tsx files, * starting from the parent block and going down each inner block, in the order the blocks were registered. */ $inner_blocks_html = '$0 <div data-block-name="woocommerce/filled-cart-block" class="wp-block-woocommerce-filled-cart-block"> <div data-block-name="woocommerce/cart-items-block" class="wp-block-woocommerce-cart-items-block"> <div data-block-name="woocommerce/cart-line-items-block" class="wp-block-woocommerce-cart-line-items-block"></div> </div> <div data-block-name="woocommerce/cart-totals-block" class="wp-block-woocommerce-cart-totals-block"> <div data-block-name="woocommerce/cart-order-summary-block" class="wp-block-woocommerce-cart-order-summary-block"></div> <div data-block-name="woocommerce/cart-express-payment-block" class="wp-block-woocommerce-cart-express-payment-block"></div> <div data-block-name="woocommerce/proceed-to-checkout-block" class="wp-block-woocommerce-proceed-to-checkout-block"></div> <div data-block-name="woocommerce/cart-accepted-payment-methods-block" class="wp-block-woocommerce-cart-accepted-payment-methods-block"></div> </div> </div> <div data-block-name="woocommerce/empty-cart-block" class="wp-block-woocommerce-empty-cart-block"> '; $content = preg_replace( '/<div class="[a-zA-Z0-9_\- ]*wp-block-woocommerce-cart[a-zA-Z0-9_\- ]*">/mi', $inner_blocks_html, $content ); $content = $content . '</div>'; } /** * Cart i3 added inner blocks for Order summary. We need to add them to Cart i2 templates. * The order needs to match the order in which these blocks were registered. */ $order_summary_with_inner_blocks = '$0 <div data-block-name="woocommerce/cart-order-summary-heading-block" class="wp-block-woocommerce-cart-order-summary-heading-block"></div> <div data-block-name="woocommerce/cart-order-summary-subtotal-block" class="wp-block-woocommerce-cart-order-summary-subtotal-block"></div> <div data-block-name="woocommerce/cart-order-summary-fee-block" class="wp-block-woocommerce-cart-order-summary-fee-block"></div> <div data-block-name="woocommerce/cart-order-summary-discount-block" class="wp-block-woocommerce-cart-order-summary-discount-block"></div> <div data-block-name="woocommerce/cart-order-summary-coupon-form-block" class="wp-block-woocommerce-cart-order-summary-coupon-form-block"></div> <div data-block-name="woocommerce/cart-order-summary-shipping-form-block" class="wp-block-woocommerce-cart-order-summary-shipping-block"></div> <div data-block-name="woocommerce/cart-order-summary-taxes-block" class="wp-block-woocommerce-cart-order-summary-taxes-block"></div> '; // 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 = '/<div[^<]*?data-block-name="woocommerce\/cart-order-summary-subtotal-block"[^>]*?>/mi'; $regex_for_order_summary = '/<div[^<]*?data-block-name="woocommerce\/cart-order-summary-block"[^>]*?>/mi'; $has_i2_template = ! preg_match( $regex_for_order_summary_subtotal, $content ); if ( $has_i2_template ) { $content = preg_replace( $regex_for_order_summary, $order_summary_with_inner_blocks, $content ); } return $content; } /** * Extra data passed through from server to client for block. * * @param array $attributes Any attributes that currently are available from the block. * Note, this will be empty in the editor context when the block is * not in the post content on editor load. */ protected function enqueue_data( array $attributes = [] ) { parent::enqueue_data( $attributes ); $this->asset_data_registry->add( 'countryData', CartCheckoutUtils::get_country_data() ); $this->asset_data_registry->add( 'displayItemizedTaxes', 'itemized' === get_option( 'woocommerce_tax_total_display' ) ); $this->asset_data_registry->add( 'displayCartPricesIncludingTax', 'incl' === get_option( 'woocommerce_tax_display_cart' ) ); $this->asset_data_registry->add( 'taxesEnabled', wc_tax_enabled() ); $this->asset_data_registry->add( 'couponsEnabled', wc_coupons_enabled() ); $this->asset_data_registry->add( 'shippingEnabled', wc_shipping_enabled() ); $this->asset_data_registry->add( 'hasDarkEditorStyleSupport', current_theme_supports( 'dark-editor-style' ) ); $this->asset_data_registry->register_page_id( isset( $attributes['checkoutPageId'] ) ? $attributes['checkoutPageId'] : 0 ); $this->asset_data_registry->add( 'isBlockTheme', wp_is_block_theme() ); $this->asset_data_registry->add( 'shippingMethodsExist', CartCheckoutUtils::shipping_methods_exist() > 0 ); $is_block_editor = $this->is_block_editor(); // Check `current_user_can` so we can show notices about incompatible extensions in the front-end to admins too. if ( ( $is_block_editor || current_user_can( 'manage_woocommerce' ) ) && ! $this->asset_data_registry->exists( 'incompatibleExtensions' ) ) { if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) && function_exists( 'get_plugins' ) ) { $declared_extensions = \Automattic\WooCommerce\Utilities\FeaturesUtil::get_compatible_plugins_for_feature( 'cart_checkout_blocks' ); $all_plugins = \get_plugins(); $incompatible_extensions = array_reduce( $declared_extensions['incompatible'], function ( array $acc, $item ) use ( $all_plugins ) { $plugin = $all_plugins[ $item ] ?? null; $plugin_id = $plugin['TextDomain'] ?? dirname( $item ); $plugin_name = $plugin['Name'] ?? $plugin_id; $acc[] = [ 'id' => $plugin_id, 'title' => $plugin_name, ]; return $acc; }, [] ); $this->asset_data_registry->add( 'incompatibleExtensions', $incompatible_extensions ); } } // Hydrate the following data depending on admin or frontend context. if ( ! is_admin() && ! WC()->is_rest_api_request() ) { $this->asset_data_registry->hydrate_api_request( '/wc/store/v1/cart' ); } /** * Fires after cart block data is registered. * * @since 2.6.0 */ do_action( 'woocommerce_blocks_cart_enqueue_data' ); } /** * Register script and style assets for the block type before it is registered. * * This registers the scripts; it does not enqueue them. */ protected function register_block_type_assets() { parent::register_block_type_assets(); $chunks = $this->get_chunks_paths( $this->chunks_folder ); $vendor_chunks = $this->get_chunks_paths( 'vendors--cart-blocks' ); $shared_chunks = []; $this->register_chunk_translations( array_merge( $chunks, $vendor_chunks, $shared_chunks ) ); } /** * Get list of Cart block & its inner-block types. * * @return array; */ public static function get_cart_block_types() { return [ 'Cart', 'CartOrderSummaryTaxesBlock', 'CartOrderSummarySubtotalBlock', 'CartOrderSummaryTotalsBlock', 'FilledCartBlock', 'EmptyCartBlock', 'CartTotalsBlock', 'CartItemsBlock', 'CartLineItemsBlock', 'CartOrderSummaryBlock', 'CartExpressPaymentBlock', 'ProceedToCheckoutBlock', 'CartAcceptedPaymentMethodsBlock', 'CartOrderSummaryCouponFormBlock', 'CartOrderSummaryDiscountBlock', 'CartOrderSummaryFeeBlock', 'CartOrderSummaryHeadingBlock', 'CartOrderSummaryShippingBlock', 'CartCrossSellsBlock', 'CartCrossSellsProductsBlock', ]; } }