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.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Blocks / BlockTypes / Cart.php
woocommerce / src / Blocks / BlockTypes Last commit date
Accordion 1 year ago AddToCartWithOptions 2 weeks 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
Cart.php
348 lines
1 <?php
2 namespace Automattic\WooCommerce\Blocks\BlockTypes;
3
4 use Automattic\WooCommerce\Blocks\Utils\CartCheckoutUtils;
5
6 /**
7 * Cart class.
8 *
9 * @internal
10 */
11 class Cart extends AbstractBlock {
12 /**
13 * Block name.
14 *
15 * @var string
16 */
17 protected $block_name = 'cart';
18
19 /**
20 * Chunks build folder.
21 *
22 * @var string
23 */
24 protected $chunks_folder = 'cart-blocks';
25
26 /**
27 * Initialize this block type.
28 *
29 * - Hook into WP lifecycle.
30 * - Register the block with WordPress.
31 */
32 protected function initialize() {
33 parent::initialize();
34 add_action( 'wp_loaded', array( $this, 'register_patterns' ) );
35 add_action( 'wp', array( $this, 'disable_wp_emoji' ) );
36 }
37
38 /**
39 * Remove WordPress emoji detection script on pages containing this block.
40 *
41 * The wp-emoji MutationObserver converts emoji text nodes to <img> elements
42 * when React hydrates or re-renders, corrupting the DOM tree and crashing the block.
43 * The wp-exclude-emoji class on the wrapper only prevents the initial parse, not the
44 * MutationObserver, so the script must be removed entirely.
45 *
46 * @since 10.8.0
47 *
48 * @return void
49 */
50 public function disable_wp_emoji() {
51 if ( has_block( $this->get_full_block_name() ) ) {
52 remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
53 remove_action( 'wp_print_styles', 'print_emoji_styles' );
54 }
55 }
56
57 /**
58 * Dequeues the scripts added by WC Core to the Cart page.
59 *
60 * @return void
61 */
62 public function dequeue_woocommerce_core_scripts() {
63 wp_dequeue_script( 'wc-cart' );
64 wp_dequeue_script( 'wc-password-strength-meter' );
65 wp_dequeue_script( 'selectWoo' );
66 wp_dequeue_style( 'select2' );
67 }
68
69 /**
70 * Register block pattern for Empty Cart Message to make it translatable.
71 */
72 public function register_patterns() {
73 $shop_permalink = wc_get_page_permalink( 'shop' );
74
75 register_block_pattern(
76 'woocommerce/cart-heading',
77 array(
78 'title' => '',
79 'inserter' => false,
80 'content' => '<!-- wp:heading {"align":"wide", "level":1} --><h1 class="wp-block-heading alignwide">' . esc_html__( 'Cart', 'woocommerce' ) . '</h1><!-- /wp:heading -->',
81 )
82 );
83 register_block_pattern(
84 'woocommerce/cart-cross-sells-message',
85 array(
86 'title' => '',
87 'inserter' => false,
88 '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 -->',
89 )
90 );
91 register_block_pattern(
92 'woocommerce/cart-empty-message',
93 array(
94 'title' => '',
95 'inserter' => false,
96 'content' => '
97 <!-- 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 -->
98 <!-- 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 -->
99 ',
100 )
101 );
102 register_block_pattern(
103 'woocommerce/cart-new-in-store-message',
104 array(
105 'title' => '',
106 'inserter' => false,
107 'content' => '<!-- wp:heading {"textAlign":"center"} --><h2 class="wp-block-heading has-text-align-center">' . esc_html__( 'New in store', 'woocommerce' ) . '</h2><!-- /wp:heading -->',
108 )
109 );
110 }
111
112 /**
113 * Get the editor script handle for this block type.
114 *
115 * @param string $key Data to get, or default to everything.
116 * @return array|string;
117 */
118 protected function get_block_type_editor_script( $key = null ) {
119 $script = [
120 'handle' => 'wc-' . $this->block_name . '-block',
121 'path' => $this->asset_api->get_block_asset_build_path( $this->block_name ),
122 'dependencies' => [ 'wc-blocks' ],
123 ];
124 return $key ? $script[ $key ] : $script;
125 }
126
127 /**
128 * Get the frontend script handle for this block type.
129 *
130 * @see $this->register_block_type()
131 * @param string $key Data to get, or default to everything.
132 * @return array|string
133 */
134 protected function get_block_type_script( $key = null ) {
135 $script = [
136 'handle' => 'wc-' . $this->block_name . '-block-frontend',
137 'path' => $this->asset_api->get_block_asset_build_path( $this->block_name . '-frontend' ),
138 'dependencies' => [],
139 ];
140 return $key ? $script[ $key ] : $script;
141 }
142
143 /**
144 * Get the frontend style handle for this block type.
145 *
146 * @return string[]
147 */
148 protected function get_block_type_style() {
149 return array_merge( parent::get_block_type_style(), [ 'wc-blocks-packages-style' ] );
150 }
151
152 /**
153 * Enqueue frontend assets for this block, just in time for rendering.
154 *
155 * @param array $attributes Any attributes that currently are available from the block.
156 * @param string $content The block content.
157 * @param WP_Block $block The block object.
158 */
159 protected function enqueue_assets( array $attributes, $content, $block ) {
160 /**
161 * Fires before cart block scripts are enqueued.
162 *
163 * @since 2.6.0
164 */
165 do_action( 'woocommerce_blocks_enqueue_cart_block_scripts_before' );
166 parent::enqueue_assets( $attributes, $content, $block );
167 /**
168 * Fires after cart block scripts are enqueued.
169 *
170 * @since 2.6.0
171 */
172 do_action( 'woocommerce_blocks_enqueue_cart_block_scripts_after' );
173 }
174
175 /**
176 * Append frontend scripts when rendering the Cart block.
177 *
178 * @param array $attributes Block attributes.
179 * @param string $content Block content.
180 * @param WP_Block $block Block instance.
181 * @return string Rendered block type output.
182 */
183 protected function render( $attributes, $content, $block ) {
184 // Dequeue the core scripts when rendering this block.
185 add_action( 'wp_enqueue_scripts', array( $this, 'dequeue_woocommerce_core_scripts' ), 20 );
186
187 /**
188 * We need to check if $content has any templates from prior iterations of the block, in order to update to the latest iteration.
189 * We test the iteration version by searching for new blocks brought in by it.
190 * The blocks used for testing should be always available in the block (not removable by the user).
191 */
192
193 $regex_for_filled_cart_block = '/<div[^<]*?data-block-name="woocommerce\/filled-cart-block"[^>]*?>/mi';
194 // Filled Cart block was added in i2, so we search for it to see if we have a Cart i1 template.
195 $has_i1_template = ! preg_match( $regex_for_filled_cart_block, $content );
196
197 if ( $has_i1_template ) {
198 /**
199 * This fallback structure needs to match the defaultTemplate variables defined in the block's edit.tsx files,
200 * starting from the parent block and going down each inner block, in the order the blocks were registered.
201 */
202 $inner_blocks_html = '$0
203 <div data-block-name="woocommerce/filled-cart-block" class="wp-block-woocommerce-filled-cart-block">
204 <div data-block-name="woocommerce/cart-items-block" class="wp-block-woocommerce-cart-items-block">
205 <div data-block-name="woocommerce/cart-line-items-block" class="wp-block-woocommerce-cart-line-items-block"></div>
206 </div>
207 <div data-block-name="woocommerce/cart-totals-block" class="wp-block-woocommerce-cart-totals-block">
208 <div data-block-name="woocommerce/cart-order-summary-block" class="wp-block-woocommerce-cart-order-summary-block"></div>
209 <div data-block-name="woocommerce/cart-express-payment-block" class="wp-block-woocommerce-cart-express-payment-block"></div>
210 <div data-block-name="woocommerce/proceed-to-checkout-block" class="wp-block-woocommerce-proceed-to-checkout-block"></div>
211 <div data-block-name="woocommerce/cart-accepted-payment-methods-block" class="wp-block-woocommerce-cart-accepted-payment-methods-block"></div>
212 </div>
213 </div>
214 <div data-block-name="woocommerce/empty-cart-block" class="wp-block-woocommerce-empty-cart-block">
215 ';
216
217 $content = preg_replace( '/<div class="[a-zA-Z0-9_\- ]*wp-block-woocommerce-cart[a-zA-Z0-9_\- ]*">/mi', $inner_blocks_html, $content );
218 $content = $content . '</div>';
219 }
220
221 /**
222 * Cart i3 added inner blocks for Order summary. We need to add them to Cart i2 templates.
223 * The order needs to match the order in which these blocks were registered.
224 */
225 $order_summary_with_inner_blocks = '$0
226 <div data-block-name="woocommerce/cart-order-summary-heading-block" class="wp-block-woocommerce-cart-order-summary-heading-block"></div>
227 <div data-block-name="woocommerce/cart-order-summary-subtotal-block" class="wp-block-woocommerce-cart-order-summary-subtotal-block"></div>
228 <div data-block-name="woocommerce/cart-order-summary-fee-block" class="wp-block-woocommerce-cart-order-summary-fee-block"></div>
229 <div data-block-name="woocommerce/cart-order-summary-discount-block" class="wp-block-woocommerce-cart-order-summary-discount-block"></div>
230 <div data-block-name="woocommerce/cart-order-summary-coupon-form-block" class="wp-block-woocommerce-cart-order-summary-coupon-form-block"></div>
231 <div data-block-name="woocommerce/cart-order-summary-shipping-form-block" class="wp-block-woocommerce-cart-order-summary-shipping-block"></div>
232 <div data-block-name="woocommerce/cart-order-summary-taxes-block" class="wp-block-woocommerce-cart-order-summary-taxes-block"></div>
233 ';
234 // Order summary subtotal block was added in i3, so we search for it to see if we have a Cart i2 template.
235 $regex_for_order_summary_subtotal = '/<div[^<]*?data-block-name="woocommerce\/cart-order-summary-subtotal-block"[^>]*?>/mi';
236 $regex_for_order_summary = '/<div[^<]*?data-block-name="woocommerce\/cart-order-summary-block"[^>]*?>/mi';
237 $has_i2_template = ! preg_match( $regex_for_order_summary_subtotal, $content );
238
239 if ( $has_i2_template ) {
240 $content = preg_replace( $regex_for_order_summary, $order_summary_with_inner_blocks, $content );
241 }
242
243 return $content;
244 }
245
246 /**
247 * Extra data passed through from server to client for block.
248 *
249 * @param array $attributes Any attributes that currently are available from the block.
250 * Note, this will be empty in the editor context when the block is
251 * not in the post content on editor load.
252 */
253 protected function enqueue_data( array $attributes = [] ) {
254 parent::enqueue_data( $attributes );
255
256 $this->asset_data_registry->add( 'countryData', CartCheckoutUtils::get_country_data() );
257 $this->asset_data_registry->add( 'displayItemizedTaxes', 'itemized' === get_option( 'woocommerce_tax_total_display' ) );
258 $this->asset_data_registry->add( 'displayCartPricesIncludingTax', 'incl' === get_option( 'woocommerce_tax_display_cart' ) );
259 $this->asset_data_registry->add( 'taxesEnabled', wc_tax_enabled() );
260 $this->asset_data_registry->add( 'couponsEnabled', wc_coupons_enabled() );
261 $this->asset_data_registry->add( 'shippingEnabled', wc_shipping_enabled() );
262 $this->asset_data_registry->add( 'hasDarkEditorStyleSupport', current_theme_supports( 'dark-editor-style' ) );
263 $this->asset_data_registry->register_page_id( isset( $attributes['checkoutPageId'] ) ? $attributes['checkoutPageId'] : 0 );
264 $this->asset_data_registry->add( 'isBlockTheme', wp_is_block_theme() );
265 $this->asset_data_registry->add( 'shippingMethodsExist', CartCheckoutUtils::shipping_methods_exist() > 0 );
266
267 $is_block_editor = $this->is_block_editor();
268
269 // Check `current_user_can` so we can show notices about incompatible extensions in the front-end to admins too.
270 if ( ( $is_block_editor || current_user_can( 'manage_woocommerce' ) ) && ! $this->asset_data_registry->exists( 'incompatibleExtensions' ) ) {
271 if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) && function_exists( 'get_plugins' ) ) {
272 $declared_extensions = \Automattic\WooCommerce\Utilities\FeaturesUtil::get_compatible_plugins_for_feature( 'cart_checkout_blocks' );
273 $all_plugins = \get_plugins();
274 $incompatible_extensions = array_reduce(
275 $declared_extensions['incompatible'],
276 function ( array $acc, $item ) use ( $all_plugins ) {
277 $plugin = $all_plugins[ $item ] ?? null;
278 $plugin_id = $plugin['TextDomain'] ?? dirname( $item );
279 $plugin_name = $plugin['Name'] ?? $plugin_id;
280 $acc[] = [
281 'id' => $plugin_id,
282 'title' => $plugin_name,
283 ];
284 return $acc;
285 },
286 []
287 );
288 $this->asset_data_registry->add( 'incompatibleExtensions', $incompatible_extensions );
289 }
290 }
291
292 // Hydrate the following data depending on admin or frontend context.
293 if ( ! is_admin() && ! WC()->is_rest_api_request() ) {
294 $this->asset_data_registry->hydrate_api_request( '/wc/store/v1/cart' );
295 }
296
297 /**
298 * Fires after cart block data is registered.
299 *
300 * @since 2.6.0
301 */
302 do_action( 'woocommerce_blocks_cart_enqueue_data' );
303 }
304
305 /**
306 * Register script and style assets for the block type before it is registered.
307 *
308 * This registers the scripts; it does not enqueue them.
309 */
310 protected function register_block_type_assets() {
311 parent::register_block_type_assets();
312 $chunks = $this->get_chunks_paths( $this->chunks_folder );
313 $vendor_chunks = $this->get_chunks_paths( 'vendors--cart-blocks' );
314 $shared_chunks = [];
315 $this->register_chunk_translations( array_merge( $chunks, $vendor_chunks, $shared_chunks ) );
316 }
317
318 /**
319 * Get list of Cart block & its inner-block types.
320 *
321 * @return array;
322 */
323 public static function get_cart_block_types() {
324 return [
325 'Cart',
326 'CartOrderSummaryTaxesBlock',
327 'CartOrderSummarySubtotalBlock',
328 'CartOrderSummaryTotalsBlock',
329 'FilledCartBlock',
330 'EmptyCartBlock',
331 'CartTotalsBlock',
332 'CartItemsBlock',
333 'CartLineItemsBlock',
334 'CartOrderSummaryBlock',
335 'CartExpressPaymentBlock',
336 'ProceedToCheckoutBlock',
337 'CartAcceptedPaymentMethodsBlock',
338 'CartOrderSummaryCouponFormBlock',
339 'CartOrderSummaryDiscountBlock',
340 'CartOrderSummaryFeeBlock',
341 'CartOrderSummaryHeadingBlock',
342 'CartOrderSummaryShippingBlock',
343 'CartCrossSellsBlock',
344 'CartCrossSellsProductsBlock',
345 ];
346 }
347 }
348