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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 / ClassicTemplate.php
woocommerce / src / Blocks / BlockTypes Last commit date
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
ClassicTemplate.php
451 lines
1 <?php
2 namespace Automattic\WooCommerce\Blocks\BlockTypes;
3
4 use Automattic\WooCommerce\Blocks\Templates\ProductAttributeTemplate;
5 use Automattic\WooCommerce\Blocks\Templates\ProductCatalogTemplate;
6 use Automattic\WooCommerce\Blocks\Templates\ProductCategoryTemplate;
7 use Automattic\WooCommerce\Blocks\Templates\ProductTagTemplate;
8 use Automattic\WooCommerce\Blocks\Templates\ProductSearchResultsTemplate;
9 use Automattic\WooCommerce\Blocks\Templates\OrderConfirmationTemplate;
10 use Automattic\WooCommerce\Blocks\Utils\StyleAttributesUtils;
11 use WC_Shortcode_Checkout;
12 use WC_Frontend_Scripts;
13
14 /**
15 * Classic Template class
16 *
17 * @internal
18 */
19 class ClassicTemplate extends AbstractDynamicBlock {
20 /**
21 * Block name.
22 *
23 * @var string
24 */
25 protected $block_name = 'legacy-template';
26
27 /**
28 * API version.
29 *
30 * @var string
31 */
32 protected $api_version = '3';
33
34 /**
35 * Initialize this block.
36 */
37 protected function initialize() {
38 parent::initialize();
39 add_filter( 'render_block', array( $this, 'add_alignment_class_to_wrapper' ), 10, 2 );
40 add_action( 'enqueue_block_assets', array( $this, 'enqueue_block_assets' ) );
41 }
42
43 /**
44 * Extra data passed through from server to client for block.
45 *
46 * @param array $attributes Any attributes that currently are available from the block.
47 * Note, this will be empty in the editor context when the block is
48 * not in the post content on editor load.
49 */
50 protected function enqueue_data( array $attributes = array() ) {
51 parent::enqueue_data( $attributes );
52
53 // Disable client-side navigation so that interactivity powered
54 // components fall back to full page reload.
55 wp_interactivity_config(
56 'core/router',
57 array(
58 'clientNavigationDisabled' => true,
59 )
60 );
61 }
62
63 /**
64 * Enqueue assets used for rendering the block in editor context.
65 *
66 * This is needed if a block is not yet within the post content--`render` and `enqueue_assets` may not have ran.
67 */
68 public function enqueue_block_assets() {
69 // Ensures frontend styles for blocks exist in the site editor iframe.
70 if ( class_exists( 'WC_Frontend_Scripts' ) && is_admin() ) {
71 $frontend_scripts = new WC_Frontend_Scripts();
72 $styles = $frontend_scripts::get_styles();
73
74 foreach ( $styles as $handle => $style ) {
75 wp_enqueue_style(
76 $handle,
77 set_url_scheme( $style['src'] ),
78 $style['deps'],
79 $style['version'],
80 $style['media']
81 );
82 }
83 }
84 }
85
86 /**
87 * Enqueue assets specific to this block.
88 *
89 * @param array $attributes Block attributes.
90 * @param string $content Block content.
91 * @param WP_Block $block Block instance.
92 */
93 protected function enqueue_assets( $attributes, $content, $block ) {
94 parent::enqueue_assets( $attributes, $content, $block );
95
96 if ( is_product() ) {
97 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_legacy_assets' ], 20 );
98 }
99 }
100
101 /**
102 * Enqueue legacy assets when this block is used as we don't enqueue them for block themes anymore.
103 *
104 * Note: This enqueue logic is intentionally duplicated in ProductImageGallery.php
105 * to keep legacy blocks independent and allow for separate deprecation paths.
106 *
107 * @see https://github.com/woocommerce/woocommerce/pull/60223
108 */
109 public function enqueue_legacy_assets() {
110 // Legacy script dependencies for backward compatibility.
111 if ( current_theme_supports( 'wc-product-gallery-zoom' ) ) {
112 wp_enqueue_script( 'wc-zoom' );
113 }
114
115 if ( current_theme_supports( 'wc-product-gallery-slider' ) ) {
116 wp_enqueue_script( 'wc-flexslider' );
117 }
118
119 if ( current_theme_supports( 'wc-product-gallery-lightbox' ) ) {
120 wp_enqueue_script( 'wc-photoswipe-ui-default' );
121 wp_enqueue_style( 'photoswipe-default-skin' );
122 add_action(
123 'wp_footer',
124 function () {
125 wc_get_template( 'single-product/photoswipe.php' );
126 }
127 );
128 }
129
130 wp_enqueue_script( 'wc-single-product' );
131 }
132
133
134 /**
135 * Render method for the Classic Template block. This method will determine which template to render.
136 *
137 * @param array $attributes Block attributes.
138 * @param string $content Block content.
139 * @param WP_Block $block Block instance.
140 * @return string | void Rendered block type output.
141 */
142 protected function render( $attributes, $content, $block ) {
143 if ( ! isset( $attributes['template'] ) ) {
144 return;
145 }
146
147 /**
148 * We need to load the scripts here because when using block templates wp_head() gets run after the block
149 * template. As a result we are trying to enqueue required scripts before we have even registered them.
150 *
151 * @see https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues/5328#issuecomment-989013447
152 */
153 if ( class_exists( 'WC_Frontend_Scripts' ) ) {
154 $frontend_scripts = new WC_Frontend_Scripts();
155 $frontend_scripts::load_scripts();
156 }
157
158 if ( OrderConfirmationTemplate::SLUG === $attributes['template'] ) {
159 return $this->render_order_received();
160 }
161
162 if ( is_product() ) {
163 add_filter( 'woocommerce_single_product_zoom_enabled', '__return_true' );
164 add_filter( 'woocommerce_single_product_photoswipe_enabled', '__return_true' );
165 add_filter( 'woocommerce_single_product_flexslider_enabled', '__return_true' );
166
167 return $this->render_single_product();
168 }
169
170 $valid = false;
171 $archive_templates = array(
172 ProductCatalogTemplate::SLUG,
173 ProductCategoryTemplate::SLUG,
174 ProductTagTemplate::SLUG,
175 ProductAttributeTemplate::SLUG,
176 ProductSearchResultsTemplate::SLUG,
177 );
178
179 // Set selected template when we directly find template base slug.
180 if ( in_array( $attributes['template'], $archive_templates, true ) ) {
181 $valid = true;
182 }
183
184 // Set selected template when we find template base slug as prefix for a specific term.
185 foreach ( $archive_templates as $template ) {
186 if ( 0 === strpos( $attributes['template'], $template ) ) {
187 $valid = true;
188 }
189 }
190
191 if ( $valid ) {
192 // Set this so that our product filters can detect if it's a PHP template.
193 $this->asset_data_registry->add( 'isRenderingPhpTemplate', true );
194
195 // Set this so filter blocks being used as widgets know when to render.
196 $this->asset_data_registry->add( 'hasFilterableProducts', true );
197
198 $this->asset_data_registry->add(
199 'pageUrl',
200 html_entity_decode( get_pagenum_link() )
201 );
202
203 return $this->render_archive_product();
204 }
205
206 ob_start();
207
208 echo "You're using the ClassicTemplate block";
209
210 wp_reset_postdata();
211
212 return ob_get_clean();
213 }
214
215 /**
216 * Render method for rendering the order confirmation template.
217 *
218 * @return string Rendered block type output.
219 */
220 protected function render_order_received() {
221 ob_start();
222
223 echo '<div class="wp-block-group">';
224
225 printf(
226 '<%1$s %2$s>%3$s</%1$s>',
227 'h1',
228 get_block_wrapper_attributes(), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
229 esc_html__( 'Order confirmation', 'woocommerce' )
230 );
231
232 WC_Shortcode_Checkout::output( array() );
233
234 echo '</div>';
235
236 return ob_get_clean();
237 }
238
239 /**
240 * Render method for the single product template and parts.
241 *
242 * @return string Rendered block type output.
243 */
244 protected function render_single_product() {
245 ob_start();
246
247 /**
248 * Hook: woocommerce_before_main_content
249 *
250 * Called before rendering the main content for a product.
251 *
252 * @see woocommerce_output_content_wrapper() Outputs opening DIV for the content (priority 10)
253 * @see woocommerce_breadcrumb() Outputs breadcrumb trail to the current product (priority 20)
254 * @see WC_Structured_Data::generate_website_data() Outputs schema markup (priority 30)
255 *
256 * @since 6.3.0
257 */
258 do_action( 'woocommerce_before_main_content' );
259
260 $product_query = new \WP_Query(
261 array(
262 'post_type' => 'product',
263 'p' => get_the_ID(),
264 )
265 );
266
267 while ( $product_query->have_posts() ) :
268
269 $product_query->the_post();
270 wc_get_template_part( 'content', 'single-product' );
271
272 endwhile;
273
274 /**
275 * Hook: woocommerce_after_main_content
276 *
277 * Called after rendering the main content for a product.
278 *
279 * @see woocommerce_output_content_wrapper_end() Outputs closing DIV for the content (priority 10)
280 *
281 * @since 6.3.0
282 */
283 do_action( 'woocommerce_after_main_content' );
284
285 wp_reset_postdata();
286
287 return ob_get_clean();
288 }
289
290 /**
291 * Render method for the archive product template and parts.
292 *
293 * @return string Rendered block type output.
294 */
295 protected function render_archive_product() {
296 ob_start();
297
298 /**
299 * Hook: woocommerce_before_main_content
300 *
301 * Called before rendering the main content for a product.
302 *
303 * @see woocommerce_output_content_wrapper() Outputs opening DIV for the content (priority 10)
304 * @see woocommerce_breadcrumb() Outputs breadcrumb trail to the current product (priority 20)
305 * @see WC_Structured_Data::generate_website_data() Outputs schema markup (priority 30)
306 *
307 * @since 6.3.0
308 */
309 do_action( 'woocommerce_before_main_content' );
310
311 ?>
312 <header class="woocommerce-products-header">
313 <?php
314 /**
315 * Hook: woocommerce_show_page_title
316 *
317 * Allows controlling the display of the page title.
318 *
319 * @since 6.3.0
320 */
321 if ( apply_filters( 'woocommerce_show_page_title', true ) ) {
322 ?>
323 <h1 class="woocommerce-products-header__title page-title">
324 <?php
325 woocommerce_page_title();
326 ?>
327 </h1>
328 <?php
329 }
330 /**
331 * Hook: woocommerce_archive_description.
332 *
333 * @see woocommerce_taxonomy_archive_description() Renders the taxonomy archive description (priority 10)
334 * @see woocommerce_product_archive_description() Renders the product archive description (priority 10)
335 *
336 * @since 6.3.0
337 */
338 do_action( 'woocommerce_archive_description' );
339 ?>
340 </header>
341 <?php
342 if ( woocommerce_product_loop() ) {
343
344 /**
345 * Hook: woocommerce_before_shop_loop.
346 *
347 * @see woocommerce_output_all_notices() Render error notices (priority 10)
348 * @see woocommerce_result_count() Show number of results found (priority 20)
349 * @see woocommerce_catalog_ordering() Show form to control sort order (priority 30)
350 *
351 * @since 6.3.0
352 */
353 do_action( 'woocommerce_before_shop_loop' );
354
355 woocommerce_product_loop_start();
356
357 if ( wc_get_loop_prop( 'total' ) ) {
358 while ( have_posts() ) {
359 the_post();
360
361 /**
362 * Hook: woocommerce_shop_loop.
363 *
364 * @since 6.3.0
365 */
366 do_action( 'woocommerce_shop_loop' );
367
368 wc_get_template_part( 'content', 'product' );
369 }
370 }
371
372 woocommerce_product_loop_end();
373
374 /**
375 * Hook: woocommerce_after_shop_loop.
376 *
377 * @see woocommerce_pagination() Renders pagination (priority 10)
378 *
379 * @since 6.3.0
380 */
381 do_action( 'woocommerce_after_shop_loop' );
382 } else {
383 /**
384 * Hook: woocommerce_no_products_found.
385 *
386 * @see wc_no_products_found() Default no products found content (priority 10)
387 *
388 * @since 6.3.0
389 */
390 do_action( 'woocommerce_no_products_found' );
391 }
392
393 /**
394 * Hook: woocommerce_after_main_content
395 *
396 * Called after rendering the main content for a product.
397 *
398 * @see woocommerce_output_content_wrapper_end() Outputs closing DIV for the content (priority 10)
399 *
400 * @since 6.3.0
401 */
402 do_action( 'woocommerce_after_main_content' );
403
404 wp_reset_postdata();
405 return ob_get_clean();
406 }
407
408 /**
409 * Get HTML markup with the right classes by attributes.
410 * This function appends the classname at the first element that have the class attribute.
411 * Based on the experience, all the wrapper elements have a class attribute.
412 *
413 * @param string $content Block content.
414 * @param array $block Parsed block data.
415 * @return string Rendered block type output.
416 */
417 public function add_alignment_class_to_wrapper( string $content, array $block ) {
418 if ( ( 'woocommerce/' . $this->block_name ) !== $block['blockName'] ) {
419 return $content;
420 }
421
422 $attributes = (array) $block['attrs'];
423
424 // Set the default alignment to wide.
425 if ( ! isset( $attributes['align'] ) ) {
426 $attributes['align'] = 'wide';
427 }
428
429 $align_class_and_style = StyleAttributesUtils::get_align_class_and_style( $attributes );
430
431 if ( ! isset( $align_class_and_style['class'] ) ) {
432 return $content;
433 }
434
435 // Find the first tag.
436 $first_tag = '<[^<>]+>';
437 $matches = array();
438 preg_match( $first_tag, $content, $matches );
439
440 // If there is a tag, but it doesn't have a class attribute, add the class attribute.
441 if ( isset( $matches[0] ) && strpos( $matches[0], ' class=' ) === false ) {
442 $pattern_before_tag_closing = '/.+?(?=>)/';
443 return preg_replace( $pattern_before_tag_closing, '$0 class="' . $align_class_and_style['class'] . '"', $content, 1 );
444 }
445
446 // If there is a tag, and it has a class already, add the class attribute.
447 $pattern_get_class = '/(?<=class=\"|\')[^"|\']+(?=\"|\')/';
448 return preg_replace( $pattern_get_class, '$0 ' . $align_class_and_style['class'], $content, 1 );
449 }
450 }
451