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