add-to-cart
4 months ago
tabs
1 year ago
back-in-stock-form.php
9 months ago
meta.php
1 year ago
photoswipe.php
9 months ago
price.php
2 years ago
product-attributes.php
1 year ago
product-image.php
5 months ago
product-thumbnails.php
1 year ago
rating.php
2 years ago
related.php
8 months ago
review-meta.php
2 years ago
review-rating.php
2 years ago
review.php
2 years ago
sale-flash.php
2 years ago
share.php
2 years ago
short-description.php
2 years ago
stock.php
2 years ago
title.php
2 years ago
up-sells.php
1 year ago
related.php
67 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Related Products |
| 4 | * |
| 5 | * This template can be overridden by copying it to yourtheme/woocommerce/single-product/related.php. |
| 6 | * |
| 7 | * HOWEVER, on occasion WooCommerce will need to update template files and you |
| 8 | * (the theme developer) will need to copy the new files to your theme to |
| 9 | * maintain compatibility. We try to do this as little as possible, but it does |
| 10 | * happen. When this occurs the version of the template file will be bumped and |
| 11 | * the readme will list any important changes. |
| 12 | * |
| 13 | * @see https://woocommerce.com/document/template-structure/ |
| 14 | * @package WooCommerce\Templates |
| 15 | * @version 10.3.0 |
| 16 | */ |
| 17 | |
| 18 | if ( ! defined( 'ABSPATH' ) ) { |
| 19 | exit; |
| 20 | } |
| 21 | |
| 22 | if ( $related_products ) : |
| 23 | /** |
| 24 | * Ensure all images of related products are lazy loaded by increasing the |
| 25 | * current media count to WordPress's lazy loading threshold if needed. |
| 26 | * Because wp_increase_content_media_count() is a private function, we |
| 27 | * check for its existence before use. |
| 28 | */ |
| 29 | if ( function_exists( 'wp_increase_content_media_count' ) ) { |
| 30 | $content_media_count = wp_increase_content_media_count( 0 ); |
| 31 | if ( $content_media_count < wp_omit_loading_attr_threshold() ) { |
| 32 | wp_increase_content_media_count( wp_omit_loading_attr_threshold() - $content_media_count ); |
| 33 | } |
| 34 | } |
| 35 | ?> |
| 36 | |
| 37 | <section class="related products"> |
| 38 | |
| 39 | <?php |
| 40 | $heading = apply_filters( 'woocommerce_product_related_products_heading', __( 'Related products', 'woocommerce' ) ); |
| 41 | |
| 42 | if ( $heading ) : |
| 43 | ?> |
| 44 | <h2><?php echo esc_html( $heading ); ?></h2> |
| 45 | <?php endif; ?> |
| 46 | <?php woocommerce_product_loop_start(); ?> |
| 47 | |
| 48 | <?php foreach ( $related_products as $related_product ) : ?> |
| 49 | |
| 50 | <?php |
| 51 | $post_object = get_post( $related_product->get_id() ); |
| 52 | |
| 53 | setup_postdata( $GLOBALS['post'] = $post_object ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited, Squiz.PHP.DisallowMultipleAssignments.Found |
| 54 | |
| 55 | wc_get_template_part( 'content', 'product' ); |
| 56 | ?> |
| 57 | |
| 58 | <?php endforeach; ?> |
| 59 | |
| 60 | <?php woocommerce_product_loop_end(); ?> |
| 61 | |
| 62 | </section> |
| 63 | <?php |
| 64 | endif; |
| 65 | |
| 66 | wp_reset_postdata(); |
| 67 |