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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 / includes / class-wc-template-loader.php
woocommerce / includes Last commit date
abstracts 5 years ago admin 5 years ago cli 5 years ago customizer 5 years ago data-stores 5 years ago emails 6 years ago export 5 years ago gateways 5 years ago import 5 years ago integrations 6 years ago interfaces 6 years ago legacy 5 years ago libraries 6 years ago log-handlers 6 years ago payment-tokens 6 years ago queue 7 years ago shipping 5 years ago shortcodes 5 years ago theme-support 6 years ago tracks 5 years ago traits 6 years ago walkers 8 years ago wccom-site 6 years ago widgets 5 years ago class-wc-ajax.php 5 years ago class-wc-api.php 6 years ago class-wc-auth.php 7 years ago class-wc-autoloader.php 6 years ago class-wc-background-emailer.php 6 years ago class-wc-background-updater.php 7 years ago class-wc-breadcrumb.php 7 years ago class-wc-cache-helper.php 5 years ago class-wc-cart-fees.php 6 years ago class-wc-cart-session.php 6 years ago class-wc-cart-totals.php 5 years ago class-wc-cart.php 5 years ago class-wc-checkout.php 5 years ago class-wc-cli.php 8 years ago class-wc-comments.php 5 years ago class-wc-countries.php 5 years ago class-wc-coupon.php 6 years ago class-wc-customer-download-log.php 8 years ago class-wc-customer-download.php 6 years ago class-wc-customer.php 7 years ago class-wc-data-exception.php 8 years ago class-wc-data-store.php 6 years ago class-wc-datetime.php 7 years ago class-wc-deprecated-action-hooks.php 8 years ago class-wc-deprecated-filter-hooks.php 7 years ago class-wc-discounts.php 6 years ago class-wc-download-handler.php 5 years ago class-wc-emails.php 6 years ago class-wc-embed.php 8 years ago class-wc-form-handler.php 5 years ago class-wc-frontend-scripts.php 6 years ago class-wc-geo-ip.php 8 years ago class-wc-geolite-integration.php 6 years ago class-wc-geolocation.php 6 years ago class-wc-https.php 8 years ago class-wc-install.php 5 years ago class-wc-integrations.php 6 years ago class-wc-log-levels.php 7 years ago class-wc-logger.php 6 years ago class-wc-meta-data.php 7 years ago class-wc-order-factory.php 6 years ago class-wc-order-item-coupon.php 5 years ago class-wc-order-item-fee.php 5 years ago class-wc-order-item-meta.php 7 years ago class-wc-order-item-product.php 5 years ago class-wc-order-item-shipping.php 5 years ago class-wc-order-item-tax.php 5 years ago class-wc-order-item.php 6 years ago class-wc-order-query.php 7 years ago class-wc-order-refund.php 8 years ago class-wc-order.php 5 years ago class-wc-payment-gateways.php 6 years ago class-wc-payment-tokens.php 6 years ago class-wc-post-data.php 6 years ago class-wc-post-types.php 5 years ago class-wc-privacy-background-process.php 8 years ago class-wc-privacy-erasers.php 6 years ago class-wc-privacy-exporters.php 6 years ago class-wc-privacy.php 6 years ago class-wc-product-attribute.php 7 years ago class-wc-product-download.php 6 years ago class-wc-product-external.php 8 years ago class-wc-product-factory.php 7 years ago class-wc-product-grouped.php 8 years ago class-wc-product-query.php 7 years ago class-wc-product-simple.php 6 years ago class-wc-product-variable.php 5 years ago class-wc-product-variation.php 5 years ago class-wc-query.php 5 years ago class-wc-rate-limiter.php 6 years ago class-wc-regenerate-images-request.php 7 years ago class-wc-regenerate-images.php 7 years ago class-wc-register-wp-admin-settings.php 8 years ago class-wc-rest-authentication.php 6 years ago class-wc-rest-exception.php 6 years ago class-wc-session-handler.php 6 years ago class-wc-shipping-rate.php 8 years ago class-wc-shipping-zone.php 6 years ago class-wc-shipping-zones.php 6 years ago class-wc-shipping.php 5 years ago class-wc-shortcodes.php 6 years ago class-wc-structured-data.php 5 years ago class-wc-tax.php 6 years ago class-wc-template-loader.php 6 years ago class-wc-tracker.php 6 years ago class-wc-validation.php 5 years ago class-wc-webhook.php 6 years ago class-woocommerce.php 5 years ago wc-account-functions.php 5 years ago wc-attribute-functions.php 5 years ago wc-cart-functions.php 5 years ago wc-conditional-functions.php 6 years ago wc-core-functions.php 5 years ago wc-coupon-functions.php 7 years ago wc-deprecated-functions.php 5 years ago wc-formatting-functions.php 5 years ago wc-notice-functions.php 6 years ago wc-order-functions.php 5 years ago wc-order-item-functions.php 6 years ago wc-page-functions.php 6 years ago wc-product-functions.php 6 years ago wc-rest-functions.php 6 years ago wc-stock-functions.php 5 years ago wc-template-functions.php 5 years ago wc-template-hooks.php 6 years ago wc-term-functions.php 6 years ago wc-update-functions.php 5 years ago wc-user-functions.php 5 years ago wc-webhook-functions.php 5 years ago wc-widget-functions.php 8 years ago
class-wc-template-loader.php
568 lines
1 <?php
2 /**
3 * Template Loader
4 *
5 * @package WooCommerce/Classes
6 */
7
8 defined( 'ABSPATH' ) || exit;
9
10 /**
11 * Template loader class.
12 */
13 class WC_Template_Loader {
14
15 /**
16 * Store the shop page ID.
17 *
18 * @var integer
19 */
20 private static $shop_page_id = 0;
21
22 /**
23 * Store whether we're processing a product inside the_content filter.
24 *
25 * @var boolean
26 */
27 private static $in_content_filter = false;
28
29 /**
30 * Is WooCommerce support defined?
31 *
32 * @var boolean
33 */
34 private static $theme_support = false;
35
36 /**
37 * Hook in methods.
38 */
39 public static function init() {
40 self::$theme_support = current_theme_supports( 'woocommerce' );
41 self::$shop_page_id = wc_get_page_id( 'shop' );
42
43 // Supported themes.
44 if ( self::$theme_support ) {
45 add_filter( 'template_include', array( __CLASS__, 'template_loader' ) );
46 add_filter( 'comments_template', array( __CLASS__, 'comments_template_loader' ) );
47 } else {
48 // Unsupported themes.
49 add_action( 'template_redirect', array( __CLASS__, 'unsupported_theme_init' ) );
50 }
51 }
52
53 /**
54 * Load a template.
55 *
56 * Handles template usage so that we can use our own templates instead of the theme's.
57 *
58 * Templates are in the 'templates' folder. WooCommerce looks for theme
59 * overrides in /theme/woocommerce/ by default.
60 *
61 * For beginners, it also looks for a woocommerce.php template first. If the user adds
62 * this to the theme (containing a woocommerce() inside) this will be used for all
63 * WooCommerce templates.
64 *
65 * @param string $template Template to load.
66 * @return string
67 */
68 public static function template_loader( $template ) {
69 if ( is_embed() ) {
70 return $template;
71 }
72
73 $default_file = self::get_template_loader_default_file();
74
75 if ( $default_file ) {
76 /**
77 * Filter hook to choose which files to find before WooCommerce does it's own logic.
78 *
79 * @since 3.0.0
80 * @var array
81 */
82 $search_files = self::get_template_loader_files( $default_file );
83 $template = locate_template( $search_files );
84
85 if ( ! $template || WC_TEMPLATE_DEBUG_MODE ) {
86 $template = WC()->plugin_path() . '/templates/' . $default_file;
87 }
88 }
89
90 return $template;
91 }
92
93 /**
94 * Get the default filename for a template.
95 *
96 * @since 3.0.0
97 * @return string
98 */
99 private static function get_template_loader_default_file() {
100 if ( is_singular( 'product' ) ) {
101 $default_file = 'single-product.php';
102 } elseif ( is_product_taxonomy() ) {
103 $object = get_queried_object();
104
105 if ( is_tax( 'product_cat' ) || is_tax( 'product_tag' ) ) {
106 $default_file = 'taxonomy-' . $object->taxonomy . '.php';
107 } else {
108 $default_file = 'archive-product.php';
109 }
110 } elseif ( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) {
111 $default_file = self::$theme_support ? 'archive-product.php' : '';
112 } else {
113 $default_file = '';
114 }
115 return $default_file;
116 }
117
118 /**
119 * Get an array of filenames to search for a given template.
120 *
121 * @since 3.0.0
122 * @param string $default_file The default file name.
123 * @return string[]
124 */
125 private static function get_template_loader_files( $default_file ) {
126 $templates = apply_filters( 'woocommerce_template_loader_files', array(), $default_file );
127 $templates[] = 'woocommerce.php';
128
129 if ( is_page_template() ) {
130 $page_template = get_page_template_slug();
131
132 if ( $page_template ) {
133 $validated_file = validate_file( $page_template );
134 if ( 0 === $validated_file ) {
135 $templates[] = $page_template;
136 } else {
137 error_log( "WooCommerce: Unable to validate template path: \"$page_template\". Error Code: $validated_file." );
138 }
139 }
140 }
141
142 if ( is_singular( 'product' ) ) {
143 $object = get_queried_object();
144 $name_decoded = urldecode( $object->post_name );
145 if ( $name_decoded !== $object->post_name ) {
146 $templates[] = "single-product-{$name_decoded}.php";
147 }
148 $templates[] = "single-product-{$object->post_name}.php";
149 }
150
151 if ( is_product_taxonomy() ) {
152 $object = get_queried_object();
153 $templates[] = 'taxonomy-' . $object->taxonomy . '-' . $object->slug . '.php';
154 $templates[] = WC()->template_path() . 'taxonomy-' . $object->taxonomy . '-' . $object->slug . '.php';
155 $templates[] = 'taxonomy-' . $object->taxonomy . '.php';
156 $templates[] = WC()->template_path() . 'taxonomy-' . $object->taxonomy . '.php';
157 }
158
159 $templates[] = $default_file;
160 $templates[] = WC()->template_path() . $default_file;
161
162 return array_unique( $templates );
163 }
164
165 /**
166 * Load comments template.
167 *
168 * @param string $template template to load.
169 * @return string
170 */
171 public static function comments_template_loader( $template ) {
172 if ( get_post_type() !== 'product' ) {
173 return $template;
174 }
175
176 $check_dirs = array(
177 trailingslashit( get_stylesheet_directory() ) . WC()->template_path(),
178 trailingslashit( get_template_directory() ) . WC()->template_path(),
179 trailingslashit( get_stylesheet_directory() ),
180 trailingslashit( get_template_directory() ),
181 trailingslashit( WC()->plugin_path() ) . 'templates/',
182 );
183
184 if ( WC_TEMPLATE_DEBUG_MODE ) {
185 $check_dirs = array( array_pop( $check_dirs ) );
186 }
187
188 foreach ( $check_dirs as $dir ) {
189 if ( file_exists( trailingslashit( $dir ) . 'single-product-reviews.php' ) ) {
190 return trailingslashit( $dir ) . 'single-product-reviews.php';
191 }
192 }
193 }
194
195 /**
196 * Unsupported theme compatibility methods.
197 */
198
199 /**
200 * Hook in methods to enhance the unsupported theme experience on pages.
201 *
202 * @since 3.3.0
203 */
204 public static function unsupported_theme_init() {
205 if ( 0 < self::$shop_page_id ) {
206 if ( is_product_taxonomy() ) {
207 self::unsupported_theme_tax_archive_init();
208 } elseif ( is_product() ) {
209 self::unsupported_theme_product_page_init();
210 } else {
211 self::unsupported_theme_shop_page_init();
212 }
213 }
214 }
215
216 /**
217 * Hook in methods to enhance the unsupported theme experience on the Shop page.
218 *
219 * @since 3.3.0
220 */
221 private static function unsupported_theme_shop_page_init() {
222 add_filter( 'the_content', array( __CLASS__, 'unsupported_theme_shop_content_filter' ), 10 );
223 add_filter( 'the_title', array( __CLASS__, 'unsupported_theme_title_filter' ), 10, 2 );
224 add_filter( 'comments_number', array( __CLASS__, 'unsupported_theme_comments_number_filter' ) );
225 }
226
227 /**
228 * Hook in methods to enhance the unsupported theme experience on Product pages.
229 *
230 * @since 3.3.0
231 */
232 private static function unsupported_theme_product_page_init() {
233 add_filter( 'the_content', array( __CLASS__, 'unsupported_theme_product_content_filter' ), 10 );
234 add_filter( 'post_thumbnail_html', array( __CLASS__, 'unsupported_theme_single_featured_image_filter' ) );
235 add_filter( 'woocommerce_product_tabs', array( __CLASS__, 'unsupported_theme_remove_review_tab' ) );
236 remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
237 remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
238 add_theme_support( 'wc-product-gallery-zoom' );
239 add_theme_support( 'wc-product-gallery-lightbox' );
240 add_theme_support( 'wc-product-gallery-slider' );
241 }
242
243 /**
244 * Enhance the unsupported theme experience on Product Category and Attribute pages by rendering
245 * those pages using the single template and shortcode-based content. To do this we make a dummy
246 * post and set a shortcode as the post content. This approach is adapted from bbPress.
247 *
248 * @since 3.3.0
249 */
250 private static function unsupported_theme_tax_archive_init() {
251 global $wp_query, $post;
252
253 $queried_object = get_queried_object();
254 $args = self::get_current_shop_view_args();
255 $shortcode_args = array(
256 'page' => $args->page,
257 'columns' => $args->columns,
258 'rows' => $args->rows,
259 'orderby' => '',
260 'order' => '',
261 'paginate' => true,
262 'cache' => false,
263 );
264
265 if ( is_product_category() ) {
266 $shortcode_args['category'] = sanitize_title( $queried_object->slug );
267 } elseif ( taxonomy_is_product_attribute( $queried_object->taxonomy ) ) {
268 $shortcode_args['attribute'] = sanitize_title( $queried_object->taxonomy );
269 $shortcode_args['terms'] = sanitize_title( $queried_object->slug );
270 } elseif ( is_product_tag() ) {
271 $shortcode_args['tag'] = sanitize_title( $queried_object->slug );
272 } else {
273 // Default theme archive for all other taxonomies.
274 return;
275 }
276
277 // Description handling.
278 if ( ! empty( $queried_object->description ) && ( empty( $_GET['product-page'] ) || 1 === absint( $_GET['product-page'] ) ) ) { // WPCS: input var ok, CSRF ok.
279 $prefix = '<div class="term-description">' . wc_format_content( $queried_object->description ) . '</div>'; // WPCS: XSS ok.
280 } else {
281 $prefix = '';
282 }
283
284 add_filter( 'woocommerce_shortcode_products_query', array( __CLASS__, 'unsupported_archive_layered_nav_compatibility' ) );
285 $shortcode = new WC_Shortcode_Products( $shortcode_args );
286 remove_filter( 'woocommerce_shortcode_products_query', array( __CLASS__, 'unsupported_archive_layered_nav_compatibility' ) );
287 $shop_page = get_post( self::$shop_page_id );
288
289 $dummy_post_properties = array(
290 'ID' => 0,
291 'post_status' => 'publish',
292 'post_author' => $shop_page->post_author,
293 'post_parent' => 0,
294 'post_type' => 'page',
295 'post_date' => $shop_page->post_date,
296 'post_date_gmt' => $shop_page->post_date_gmt,
297 'post_modified' => $shop_page->post_modified,
298 'post_modified_gmt' => $shop_page->post_modified_gmt,
299 'post_content' => $prefix . $shortcode->get_content(),
300 'post_title' => wc_clean( $queried_object->name ),
301 'post_excerpt' => '',
302 'post_content_filtered' => '',
303 'post_mime_type' => '',
304 'post_password' => '',
305 'post_name' => $queried_object->slug,
306 'guid' => '',
307 'menu_order' => 0,
308 'pinged' => '',
309 'to_ping' => '',
310 'ping_status' => '',
311 'comment_status' => 'closed',
312 'comment_count' => 0,
313 'filter' => 'raw',
314 );
315
316 // Set the $post global.
317 $post = new WP_Post( (object) $dummy_post_properties ); // @codingStandardsIgnoreLine.
318
319 // Copy the new post global into the main $wp_query.
320 $wp_query->post = $post;
321 $wp_query->posts = array( $post );
322
323 // Prevent comments form from appearing.
324 $wp_query->post_count = 1;
325 $wp_query->is_404 = false;
326 $wp_query->is_page = true;
327 $wp_query->is_single = true;
328 $wp_query->is_archive = false;
329 $wp_query->is_tax = true;
330 $wp_query->max_num_pages = 0;
331
332 // Prepare everything for rendering.
333 setup_postdata( $post );
334 remove_all_filters( 'the_content' );
335 remove_all_filters( 'the_excerpt' );
336 add_filter( 'template_include', array( __CLASS__, 'force_single_template_filter' ) );
337 }
338
339 /**
340 * Add layered nav args to WP_Query args generated by the 'products' shortcode.
341 *
342 * @since 3.3.4
343 * @param array $query WP_Query args.
344 * @return array
345 */
346 public static function unsupported_archive_layered_nav_compatibility( $query ) {
347 foreach ( WC()->query->get_layered_nav_chosen_attributes() as $taxonomy => $data ) {
348 $query['tax_query'][] = array(
349 'taxonomy' => $taxonomy,
350 'field' => 'slug',
351 'terms' => $data['terms'],
352 'operator' => 'and' === $data['query_type'] ? 'AND' : 'IN',
353 'include_children' => false,
354 );
355 }
356 return $query;
357 }
358
359 /**
360 * Force the loading of one of the single templates instead of whatever template was about to be loaded.
361 *
362 * @since 3.3.0
363 * @param string $template Path to template.
364 * @return string
365 */
366 public static function force_single_template_filter( $template ) {
367 $possible_templates = array(
368 'page',
369 'single',
370 'singular',
371 'index',
372 );
373
374 foreach ( $possible_templates as $possible_template ) {
375 $path = get_query_template( $possible_template );
376 if ( $path ) {
377 return $path;
378 }
379 }
380
381 return $template;
382 }
383
384 /**
385 * Get information about the current shop page view.
386 *
387 * @since 3.3.0
388 * @return array
389 */
390 private static function get_current_shop_view_args() {
391 return (object) array(
392 'page' => absint( max( 1, absint( get_query_var( 'paged' ) ) ) ),
393 'columns' => wc_get_default_products_per_row(),
394 'rows' => wc_get_default_product_rows_per_page(),
395 );
396 }
397
398 /**
399 * Filter the title and insert WooCommerce content on the shop page.
400 *
401 * For non-WC themes, this will setup the main shop page to be shortcode based to improve default appearance.
402 *
403 * @since 3.3.0
404 * @param string $title Existing title.
405 * @param int $id ID of the post being filtered.
406 * @return string
407 */
408 public static function unsupported_theme_title_filter( $title, $id ) {
409 if ( self::$theme_support || ! $id !== self::$shop_page_id ) {
410 return $title;
411 }
412
413 if ( is_page( self::$shop_page_id ) || ( is_home() && 'page' === get_option( 'show_on_front' ) && absint( get_option( 'page_on_front' ) ) === self::$shop_page_id ) ) {
414 $args = self::get_current_shop_view_args();
415 $title_suffix = array();
416
417 if ( $args->page > 1 ) {
418 /* translators: %d: Page number. */
419 $title_suffix[] = sprintf( esc_html__( 'Page %d', 'woocommerce' ), $args->page );
420 }
421
422 if ( $title_suffix ) {
423 $title = $title . ' &ndash; ' . implode( ', ', $title_suffix );
424 }
425 }
426 return $title;
427 }
428
429 /**
430 * Filter the content and insert WooCommerce content on the shop page.
431 *
432 * For non-WC themes, this will setup the main shop page to be shortcode based to improve default appearance.
433 *
434 * @since 3.3.0
435 * @param string $content Existing post content.
436 * @return string
437 */
438 public static function unsupported_theme_shop_content_filter( $content ) {
439 global $wp_query;
440
441 if ( self::$theme_support || ! is_main_query() || ! in_the_loop() ) {
442 return $content;
443 }
444
445 self::$in_content_filter = true;
446
447 // Remove the filter we're in to avoid nested calls.
448 remove_filter( 'the_content', array( __CLASS__, 'unsupported_theme_shop_content_filter' ) );
449
450 // Unsupported theme shop page.
451 if ( is_page( self::$shop_page_id ) ) {
452 $args = self::get_current_shop_view_args();
453 $shortcode = new WC_Shortcode_Products(
454 array_merge(
455 WC()->query->get_catalog_ordering_args(),
456 array(
457 'page' => $args->page,
458 'columns' => $args->columns,
459 'rows' => $args->rows,
460 'orderby' => '',
461 'order' => '',
462 'paginate' => true,
463 'cache' => false,
464 )
465 ),
466 'products'
467 );
468
469 // Allow queries to run e.g. layered nav.
470 add_action( 'pre_get_posts', array( WC()->query, 'product_query' ) );
471
472 $content = $content . $shortcode->get_content();
473
474 // Remove actions and self to avoid nested calls.
475 remove_action( 'pre_get_posts', array( WC()->query, 'product_query' ) );
476 WC()->query->remove_ordering_args();
477 }
478
479 self::$in_content_filter = false;
480
481 return $content;
482 }
483
484 /**
485 * Filter the content and insert WooCommerce content on the shop page.
486 *
487 * For non-WC themes, this will setup the main shop page to be shortcode based to improve default appearance.
488 *
489 * @since 3.3.0
490 * @param string $content Existing post content.
491 * @return string
492 */
493 public static function unsupported_theme_product_content_filter( $content ) {
494 global $wp_query;
495
496 if ( self::$theme_support || ! is_main_query() || ! in_the_loop() ) {
497 return $content;
498 }
499
500 self::$in_content_filter = true;
501
502 // Remove the filter we're in to avoid nested calls.
503 remove_filter( 'the_content', array( __CLASS__, 'unsupported_theme_product_content_filter' ) );
504
505 if ( is_product() ) {
506 $content = do_shortcode( '[product_page id="' . get_the_ID() . '" show_title=0 status="any"]' );
507 }
508
509 self::$in_content_filter = false;
510
511 return $content;
512 }
513
514 /**
515 * Suppress the comments number on the Shop page for unsupported themes since there is no commenting on the Shop page.
516 *
517 * @since 3.4.5
518 * @param string $comments_number The comments number text.
519 * @return string
520 */
521 public static function unsupported_theme_comments_number_filter( $comments_number ) {
522 if ( is_page( self::$shop_page_id ) ) {
523 return '';
524 }
525
526 return $comments_number;
527 }
528
529 /**
530 * Are we filtering content for unsupported themes?
531 *
532 * @since 3.3.2
533 * @return bool
534 */
535 public static function in_content_filter() {
536 return (bool) self::$in_content_filter;
537 }
538
539 /**
540 * Prevent the main featured image on product pages because there will be another featured image
541 * in the gallery.
542 *
543 * @since 3.3.0
544 * @param string $html Img element HTML.
545 * @return string
546 */
547 public static function unsupported_theme_single_featured_image_filter( $html ) {
548 if ( self::in_content_filter() || ! is_product() || ! is_main_query() ) {
549 return $html;
550 }
551
552 return '';
553 }
554
555 /**
556 * Remove the Review tab and just use the regular comment form.
557 *
558 * @param array $tabs Tab info.
559 * @return array
560 */
561 public static function unsupported_theme_remove_review_tab( $tabs ) {
562 unset( $tabs['reviews'] );
563 return $tabs;
564 }
565 }
566
567 add_action( 'init', array( 'WC_Template_Loader', 'init' ) );
568