暫無描述

related.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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://docs.woocommerce.com/document/template-structure/
  14. * @package WooCommerce\Templates
  15. * @version 3.9.0
  16. */
  17. if ( ! defined( 'ABSPATH' ) ) {
  18. exit;
  19. }
  20. if ( $related_products ) : ?>
  21. <section class="related products">
  22. <?php
  23. $heading = apply_filters( 'woocommerce_product_related_products_heading', __( 'Related products', 'woocommerce' ) );
  24. if ( $heading ) :
  25. ?>
  26. <h2><?php echo esc_html( $heading ); ?></h2>
  27. <?php endif; ?>
  28. <?php woocommerce_product_loop_start(); ?>
  29. <?php foreach ( $related_products as $related_product ) : ?>
  30. <?php
  31. $post_object = get_post( $related_product->get_id() );
  32. setup_postdata( $GLOBALS['post'] =& $post_object ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited, Squiz.PHP.DisallowMultipleAssignments.Found
  33. wc_get_template_part( 'content', 'product' );
  34. ?>
  35. <?php endforeach; ?>
  36. <?php woocommerce_product_loop_end(); ?>
  37. </section>
  38. <?php
  39. endif;
  40. wp_reset_postdata();