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.0.1 5.2.0-beta.1 10.0.2 5.2.0-rc.1 10.0.3 5.2.0-rc.2 10.0.4 5.2.1 10.0.5 5.2.2 10.0.6 5.2.3 10.1.0 5.2.4 10.1.0-rc.1 5.2.5 10.1.0-rc.2 5.3.0 10.1.0-rc.3 5.3.0-beta.1 10.1.0-rc.4 5.3.0-rc.1 10.1.1 5.3.0-rc.2 10.1.2 5.3.1 10.1.3 5.3.2 10.1.4 5.3.3 10.2.0 5.4.0 10.2.0-beta.1 5.4.0-beta.1 10.2.0-beta.2 5.4.0-rc.1 10.2.0-rc.1 5.4.1 10.2.1 5.4.2 10.2.2 5.4.3 10.2.3 5.4.4 10.2.4 5.4.5 10.3.0 5.5.0 10.3.0-beta.1 5.5.0-beta.1 10.3.0-beta.2 5.5.0-rc.1 10.3.0-rc.1 5.5.0-rc.2 10.3.0-rc.2 5.5.1 10.3.1 5.5.2 10.3.2 5.5.3 10.3.3 5.5.4 10.3.4 5.5.5 10.3.5 5.6.0 10.3.6 5.6.0-beta.1 10.3.7 5.6.0-rc.1 10.3.8 5.6.0-rc.2 10.4.0 5.6.1 10.4.0-beta.1 5.6.2 10.4.0-beta.2 5.6.3 10.4.0-rc.1 5.7.0 10.4.1 5.7.0-beta.1 10.4.2 5.7.0-rc.1 10.4.3 5.7.1 10.4.4 5.7.2 10.5.0 5.7.3 10.5.0-beta.1 5.8.0 10.5.0-beta.2 5.8.0-beta.1 10.5.0-rc.1 5.8.0-beta.2 10.5.0-rc.2 5.8.0-rc.1 10.5.0-rc.3 5.8.1 10.5.1 5.8.2 10.5.2 5.9.0 10.5.3 5.9.0-beta.1 10.6.0 5.9.0-rc.1 10.6.0-beta.1 5.9.0-rc.2 10.6.0-beta.2 5.9.1 10.6.0-rc.1 5.9.2 10.6.1 6.0.0 10.6.2 6.0.0-beta.1 10.7.0 6.0.0-rc.1 10.7.0-beta.1 6.0.1 10.7.0-beta.2 6.0.2 10.7.0-rc.1 6.1.0 3.0.0 6.1.0-beta.1 3.0.1 6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c.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 weeks ago ProductCollection 2 weeks ago Reviews 2 weeks ago AbstractBlock.php 2 weeks ago AbstractDynamicBlock.php 2 years ago AbstractInnerBlock.php 1 year ago AbstractProductGrid.php 5 months ago ActiveFilters.php 2 years ago AddToCartForm.php 2 weeks ago AddToWishlistButton.php 2 months ago AllProducts.php 1 month ago AllReviews.php 2 years ago AtomicBlock.php 2 years ago AttributeFilter.php 1 year ago Breadcrumbs.php 1 month ago Cart.php 2 weeks 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 3 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 2 months ago CategoryDescription.php 3 months ago CategoryTitle.php 3 months ago Checkout.php 2 weeks ago CheckoutActionsBlock.php 1 year ago CheckoutAdditionalInformationBlock.php 2 years ago CheckoutBillingAddressBlock.php 2 years ago CheckoutContactInformationBlock.php 2 years ago CheckoutExpressPaymentBlock.php 10 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 6 months ago ComingSoon.php 1 year ago CouponCode.php 2 weeks ago CustomerAccount.php 2 weeks ago Dropdown.php 1 month ago EmailContent.php 2 weeks ago EmptyCartBlock.php 2 years ago EmptyMiniCartContentsBlock.php 2 weeks ago EnableBlockJsonAssetsTrait.php 1 year ago FeaturedCategory.php 2 weeks ago FeaturedItem.php 2 weeks ago FeaturedProduct.php 2 weeks ago FilledCartBlock.php 2 years ago FilledMiniCartContentsBlock.php 2 weeks ago FilterWrapper.php 2 years ago HandpickedProducts.php 1 year ago MiniCart.php 2 weeks ago MiniCartCartButtonBlock.php 2 weeks ago MiniCartCheckoutButtonBlock.php 2 weeks ago MiniCartContents.php 2 weeks ago MiniCartFooterBlock.php 2 weeks ago MiniCartItemsBlock.php 2 weeks ago MiniCartProductsTableBlock.php 2 weeks ago MiniCartShoppingButtonBlock.php 2 weeks ago MiniCartTitleBlock.php 2 weeks ago MiniCartTitleItemsCounterBlock.php 2 weeks ago MiniCartTitleLabelBlock.php 2 weeks ago NextPreviousButtons.php 7 months ago PageContentWrapper.php 2 years ago PaymentMethodIcons.php 1 year ago PriceFilter.php 1 year ago ProceedToCheckoutBlock.php 2 years ago ProductAverageRating.php 1 year ago ProductBestSellers.php 2 years ago ProductButton.php 2 weeks ago ProductCategories.php 2 months ago ProductCategory.php 2 years ago ProductDescription.php 10 months ago ProductDetails.php 7 months ago ProductFilterActive.php 2 months ago ProductFilterAttribute.php 1 month ago ProductFilterCheckboxList.php 2 months ago ProductFilterChips.php 2 months ago ProductFilterClearButton.php 2 months ago ProductFilterPrice.php 2 months ago ProductFilterPriceSlider.php 2 months ago ProductFilterRating.php 2 months ago ProductFilterRemovableChips.php 2 months ago ProductFilterStatus.php 1 month ago ProductFilterTaxonomy.php 1 month ago ProductFilters.php 1 month ago ProductGallery.php 2 weeks ago ProductGalleryLargeImage.php 2 weeks ago ProductGalleryThumbnails.php 2 weeks ago ProductImage.php 2 weeks ago ProductImageGallery.php 9 months ago ProductMeta.php 2 years ago ProductNew.php 2 years ago ProductOnSale.php 2 years ago ProductPrice.php 2 weeks ago ProductQuery.php 1 month ago ProductRating.php 1 year ago ProductRatingCounter.php 1 year ago ProductRatingStars.php 1 year ago ProductResultsCount.php 3 months ago ProductSKU.php 3 months ago ProductSaleBadge.php 1 year ago ProductSearch.php 1 year ago ProductSpecifications.php 3 months ago ProductStockIndicator.php 3 months ago ProductSummary.php 3 weeks ago ProductTag.php 2 years ago ProductTemplate.php 1 month ago ProductTitle.php 1 year ago ProductTopRated.php 2 years ago ProductsByAttribute.php 2 years ago RatingFilter.php 2 years ago RelatedProducts.php 5 months ago ReviewsByCategory.php 2 years ago ReviewsByProduct.php 2 years ago SavedForLater.php 2 months ago SingleProduct.php 2 weeks ago StockFilter.php 2 weeks ago StoreNotices.php 1 year ago Wishlist.php 2 months ago
Cart.php
334 lines
1 <?php
2 namespace Automattic\WooCommerce\Blocks\BlockTypes;
3
4 use Automattic\WooCommerce\Blocks\Utils\CartCheckoutUtils;
5 use Automattic\WooCommerce\Enums\TaxDisplayMode;
6
7 /**
8 * Cart class.
9 *
10 * @internal
11 */
12 class Cart extends AbstractBlock {
13 /**
14 * Block name.
15 *
16 * @var string
17 */
18 protected $block_name = 'cart';
19
20 /**
21 * Chunks build folder.
22 *
23 * @var string
24 */
25 protected $chunks_folder = 'cart-blocks';
26
27 /**
28 * Initialize this block type.
29 *
30 * - Hook into WP lifecycle.
31 * - Register the block with WordPress.
32 */
33 protected function initialize() {
34 parent::initialize();
35 add_action( 'wp_loaded', array( $this, 'register_patterns' ) );
36 add_action( 'wp', array( $this, 'disable_wp_emoji' ) );
37 }
38
39 /**
40 * Remove WordPress emoji detection script on pages containing this block.
41 *
42 * The wp-emoji MutationObserver converts emoji text nodes to <img> elements
43 * when React hydrates or re-renders, corrupting the DOM tree and crashing the block.
44 * The wp-exclude-emoji class on the wrapper only prevents the initial parse, not the
45 * MutationObserver, so the script must be removed entirely.
46 *
47 * @since 10.8.0
48 *
49 * @return void
50 */
51 public function disable_wp_emoji() {
52 if ( has_block( $this->get_full_block_name() ) ) {
53 remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
54 remove_action( 'wp_print_styles', 'print_emoji_styles' );
55 }
56 }
57
58 /**
59 * Dequeues the scripts added by WC Core to the Cart page.
60 *
61 * @return void
62 */
63 public function dequeue_woocommerce_core_scripts() {
64 wp_dequeue_script( 'wc-cart' );
65 wp_dequeue_script( 'wc-password-strength-meter' );
66 wp_dequeue_script( 'selectWoo' );
67 wp_dequeue_style( 'select2' );
68 }
69
70 /**
71 * Register block pattern for Empty Cart Message to make it translatable.
72 */
73 public function register_patterns() {
74 $shop_permalink = wc_get_page_permalink( 'shop' );
75
76 register_block_pattern(
77 'woocommerce/cart-heading',
78 array(
79 'title' => '',
80 'inserter' => false,
81 'content' => '<!-- wp:heading {"align":"wide", "level":1} --><h1 class="wp-block-heading alignwide">' . esc_html__( 'Cart', 'woocommerce' ) . '</h1><!-- /wp:heading -->',
82 )
83 );
84 register_block_pattern(
85 'woocommerce/cart-cross-sells-message',
86 array(
87 'title' => '',
88 'inserter' => false,
89 '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 -->',
90 )
91 );
92 register_block_pattern(
93 'woocommerce/cart-empty-message',
94 array(
95 'title' => '',
96 'inserter' => false,
97 'content' => '
98 <!-- 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 -->
99 <!-- 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 -->
100 ',
101 )
102 );
103 register_block_pattern(
104 'woocommerce/cart-new-in-store-message',
105 array(
106 'title' => '',
107 'inserter' => false,
108 'content' => '<!-- wp:heading {"textAlign":"center"} --><h2 class="wp-block-heading has-text-align-center">' . esc_html__( 'New in store', 'woocommerce' ) . '</h2><!-- /wp:heading -->',
109 )
110 );
111 }
112
113 /**
114 * Get the frontend script handle for this block type.
115 *
116 * @see $this->register_block_type()
117 * @param string $key Data to get, or default to everything.
118 * @return array|string
119 */
120 protected function get_block_type_script( $key = null ) {
121 $script = [
122 'handle' => 'wc-' . $this->block_name . '-block-frontend',
123 'path' => $this->asset_api->get_block_asset_build_path( $this->block_name . '-frontend' ),
124 'dependencies' => [],
125 ];
126 return $key ? $script[ $key ] : $script;
127 }
128
129 /**
130 * Get the frontend style handle for this block type.
131 *
132 * @return string[]
133 */
134 protected function get_block_type_style() {
135 return array_merge( parent::get_block_type_style(), [ 'wc-blocks-packages-style' ] );
136 }
137
138 /**
139 * Enqueue frontend assets for this block, just in time for rendering.
140 *
141 * @param array $attributes Any attributes that currently are available from the block.
142 * @param string $content The block content.
143 * @param WP_Block $block The block object.
144 */
145 protected function enqueue_assets( array $attributes, $content, $block ) {
146 /**
147 * Fires before cart block scripts are enqueued.
148 *
149 * @since 2.6.0
150 */
151 do_action( 'woocommerce_blocks_enqueue_cart_block_scripts_before' );
152 parent::enqueue_assets( $attributes, $content, $block );
153 /**
154 * Fires after cart block scripts are enqueued.
155 *
156 * @since 2.6.0
157 */
158 do_action( 'woocommerce_blocks_enqueue_cart_block_scripts_after' );
159 }
160
161 /**
162 * Append frontend scripts when rendering the Cart block.
163 *
164 * @param array $attributes Block attributes.
165 * @param string $content Block content.
166 * @param WP_Block $block Block instance.
167 * @return string Rendered block type output.
168 */
169 protected function render( $attributes, $content, $block ) {
170 // Dequeue the core scripts when rendering this block.
171 add_action( 'wp_enqueue_scripts', array( $this, 'dequeue_woocommerce_core_scripts' ), 20 );
172
173 /**
174 * We need to check if $content has any templates from prior iterations of the block, in order to update to the latest iteration.
175 * We test the iteration version by searching for new blocks brought in by it.
176 * The blocks used for testing should be always available in the block (not removable by the user).
177 */
178
179 $regex_for_filled_cart_block = '/<div[^<]*?data-block-name="woocommerce\/filled-cart-block"[^>]*?>/mi';
180 // Filled Cart block was added in i2, so we search for it to see if we have a Cart i1 template.
181 $has_i1_template = ! preg_match( $regex_for_filled_cart_block, $content );
182
183 if ( $has_i1_template ) {
184 /**
185 * This fallback structure needs to match the defaultTemplate variables defined in the block's edit.tsx files,
186 * starting from the parent block and going down each inner block, in the order the blocks were registered.
187 */
188 $inner_blocks_html = '$0
189 <div data-block-name="woocommerce/filled-cart-block" class="wp-block-woocommerce-filled-cart-block">
190 <div data-block-name="woocommerce/cart-items-block" class="wp-block-woocommerce-cart-items-block">
191 <div data-block-name="woocommerce/cart-line-items-block" class="wp-block-woocommerce-cart-line-items-block"></div>
192 </div>
193 <div data-block-name="woocommerce/cart-totals-block" class="wp-block-woocommerce-cart-totals-block">
194 <div data-block-name="woocommerce/cart-order-summary-block" class="wp-block-woocommerce-cart-order-summary-block"></div>
195 <div data-block-name="woocommerce/cart-express-payment-block" class="wp-block-woocommerce-cart-express-payment-block"></div>
196 <div data-block-name="woocommerce/proceed-to-checkout-block" class="wp-block-woocommerce-proceed-to-checkout-block"></div>
197 <div data-block-name="woocommerce/cart-accepted-payment-methods-block" class="wp-block-woocommerce-cart-accepted-payment-methods-block"></div>
198 </div>
199 </div>
200 <div data-block-name="woocommerce/empty-cart-block" class="wp-block-woocommerce-empty-cart-block">
201 ';
202
203 $content = preg_replace( '/<div class="[a-zA-Z0-9_\- ]*wp-block-woocommerce-cart[a-zA-Z0-9_\- ]*">/mi', $inner_blocks_html, $content );
204 $content = $content . '</div>';
205 }
206
207 /**
208 * Cart i3 added inner blocks for Order summary. We need to add them to Cart i2 templates.
209 * The order needs to match the order in which these blocks were registered.
210 */
211 $order_summary_with_inner_blocks = '$0
212 <div data-block-name="woocommerce/cart-order-summary-heading-block" class="wp-block-woocommerce-cart-order-summary-heading-block"></div>
213 <div data-block-name="woocommerce/cart-order-summary-subtotal-block" class="wp-block-woocommerce-cart-order-summary-subtotal-block"></div>
214 <div data-block-name="woocommerce/cart-order-summary-fee-block" class="wp-block-woocommerce-cart-order-summary-fee-block"></div>
215 <div data-block-name="woocommerce/cart-order-summary-discount-block" class="wp-block-woocommerce-cart-order-summary-discount-block"></div>
216 <div data-block-name="woocommerce/cart-order-summary-coupon-form-block" class="wp-block-woocommerce-cart-order-summary-coupon-form-block"></div>
217 <div data-block-name="woocommerce/cart-order-summary-shipping-form-block" class="wp-block-woocommerce-cart-order-summary-shipping-block"></div>
218 <div data-block-name="woocommerce/cart-order-summary-taxes-block" class="wp-block-woocommerce-cart-order-summary-taxes-block"></div>
219 ';
220 // Order summary subtotal block was added in i3, so we search for it to see if we have a Cart i2 template.
221 $regex_for_order_summary_subtotal = '/<div[^<]*?data-block-name="woocommerce\/cart-order-summary-subtotal-block"[^>]*?>/mi';
222 $regex_for_order_summary = '/<div[^<]*?data-block-name="woocommerce\/cart-order-summary-block"[^>]*?>/mi';
223 $has_i2_template = ! preg_match( $regex_for_order_summary_subtotal, $content );
224
225 if ( $has_i2_template ) {
226 $content = preg_replace( $regex_for_order_summary, $order_summary_with_inner_blocks, $content );
227 }
228
229 return $content;
230 }
231
232 /**
233 * Extra data passed through from server to client for block.
234 *
235 * @param array $attributes Any attributes that currently are available from the block.
236 * Note, this will be empty in the editor context when the block is
237 * not in the post content on editor load.
238 */
239 protected function enqueue_data( array $attributes = [] ) {
240 parent::enqueue_data( $attributes );
241
242 $this->asset_data_registry->add( 'countryData', CartCheckoutUtils::get_country_data() );
243 $this->asset_data_registry->add( 'displayItemizedTaxes', 'itemized' === get_option( 'woocommerce_tax_total_display' ) );
244 $this->asset_data_registry->add( 'displayCartPricesIncludingTax', TaxDisplayMode::INCLUSIVE === get_option( 'woocommerce_tax_display_cart' ) );
245 $this->asset_data_registry->add( 'taxesEnabled', wc_tax_enabled() );
246 $this->asset_data_registry->add( 'couponsEnabled', wc_coupons_enabled() );
247 $this->asset_data_registry->add( 'shippingEnabled', wc_shipping_enabled() );
248 $this->asset_data_registry->add( 'hasDarkEditorStyleSupport', current_theme_supports( 'dark-editor-style' ) );
249 $this->asset_data_registry->register_page_id( isset( $attributes['checkoutPageId'] ) ? $attributes['checkoutPageId'] : 0 );
250 $this->asset_data_registry->add( 'isBlockTheme', wp_is_block_theme() );
251 $this->asset_data_registry->add( 'shippingMethodsExist', CartCheckoutUtils::shipping_methods_exist() > 0 );
252
253 $is_block_editor = $this->is_block_editor();
254
255 // Check `current_user_can` so we can show notices about incompatible extensions in the front-end to admins too.
256 if ( ( $is_block_editor || current_user_can( 'manage_woocommerce' ) ) && ! $this->asset_data_registry->exists( 'incompatibleExtensions' ) ) {
257 if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) && function_exists( 'get_plugins' ) ) {
258 $declared_extensions = \Automattic\WooCommerce\Utilities\FeaturesUtil::get_compatible_plugins_for_feature( 'cart_checkout_blocks' );
259 $all_plugins = \get_plugins();
260 $incompatible_extensions = array_reduce(
261 $declared_extensions['incompatible'],
262 function ( array $acc, $item ) use ( $all_plugins ) {
263 $plugin = $all_plugins[ $item ] ?? null;
264 $plugin_id = $plugin['TextDomain'] ?? dirname( $item );
265 $plugin_name = $plugin['Name'] ?? $plugin_id;
266 $acc[] = [
267 'id' => $plugin_id,
268 'title' => $plugin_name,
269 ];
270 return $acc;
271 },
272 []
273 );
274 $this->asset_data_registry->add( 'incompatibleExtensions', $incompatible_extensions );
275 }
276 }
277
278 // Hydrate the following data depending on admin or frontend context.
279 if ( ! is_admin() && ! WC()->is_rest_api_request() ) {
280 $this->asset_data_registry->hydrate_api_request( '/wc/store/v1/cart' );
281 }
282
283 /**
284 * Fires after cart block data is registered.
285 *
286 * @since 2.6.0
287 */
288 do_action( 'woocommerce_blocks_cart_enqueue_data' );
289 }
290
291 /**
292 * Register script and style assets for the block type before it is registered.
293 *
294 * This registers the scripts; it does not enqueue them.
295 */
296 protected function register_block_type_assets() {
297 parent::register_block_type_assets();
298 $chunks = $this->get_chunks_paths( $this->chunks_folder );
299 $vendor_chunks = $this->get_chunks_paths( 'vendors--cart-blocks' );
300 $shared_chunks = [];
301 $this->register_chunk_translations( array_merge( $chunks, $vendor_chunks, $shared_chunks ) );
302 }
303
304 /**
305 * Get list of Cart block & its inner-block types.
306 *
307 * @return array;
308 */
309 public static function get_cart_block_types() {
310 return [
311 'Cart',
312 'CartOrderSummaryTaxesBlock',
313 'CartOrderSummarySubtotalBlock',
314 'CartOrderSummaryTotalsBlock',
315 'FilledCartBlock',
316 'EmptyCartBlock',
317 'CartTotalsBlock',
318 'CartItemsBlock',
319 'CartLineItemsBlock',
320 'CartOrderSummaryBlock',
321 'CartExpressPaymentBlock',
322 'ProceedToCheckoutBlock',
323 'CartAcceptedPaymentMethodsBlock',
324 'CartOrderSummaryCouponFormBlock',
325 'CartOrderSummaryDiscountBlock',
326 'CartOrderSummaryFeeBlock',
327 'CartOrderSummaryHeadingBlock',
328 'CartOrderSummaryShippingBlock',
329 'CartCrossSellsBlock',
330 'CartCrossSellsProductsBlock',
331 ];
332 }
333 }
334