Advertisement
son86000

related.php

Jul 16th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.05 KB | None | 0 0
  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.  * @author      WooThemes
  15.  * @package     WooCommerce/Templates
  16.  * @version     3.0.0
  17.  */
  18.  
  19. if ( ! defined( 'ABSPATH' ) ) {
  20.     exit;
  21. }
  22.  
  23. if ( $related_products ) : ?>
  24.  
  25.     <section class="related products">
  26.  
  27.         <h2><?php esc_html_e( 'Related products', 'woocommerce' ); ?></h2>
  28.  
  29.         <?php woocommerce_product_loop_start(); ?>
  30.  
  31.             <?php foreach ( $related_products as $related_product ) : ?>
  32.  
  33.                 <?php
  34.  
  35.                     $post = 40;
  36.                    
  37.                     $post_object = get_post( $related_product->get_id() );
  38.  
  39.                     setup_postdata( $GLOBALS['post'] =& $post_object );
  40.  
  41.                     wc_get_template_part( 'content', 'product' );
  42.                    
  43.                     wp_get_post_terms('$post_object');
  44.                    
  45.                     ?>
  46.  
  47.                    
  48.  
  49.             <?php endforeach; ?>
  50.  
  51.             <?php
  52.                    
  53.                     $loop = new WP_Query( array(
  54.                         'post_type' => 'product',
  55.                         'post_status' => 'publish',
  56.                         'posts_per_page' => 12,
  57.                         'category' => $post,
  58.                         'tax_query' => array( array(
  59.                             'taxonomy'         => 'product_cat',
  60.                             'field'            => 'slug', // Or 'term_id' or 'name'
  61.                             'terms'            => get_query_var( 'product_cat' ), // A slug term
  62.                             // 'include_children' => false // or true (optional)
  63.                         )),
  64.                         'orderby' => 'rand'
  65.                     ) );
  66.                    
  67.                     ?>
  68.  
  69.         <?php woocommerce_product_loop_end(); ?>
  70.  
  71.     </section>
  72.  
  73. <?php endif;
  74.  
  75. wp_reset_postdata();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement