<?php
/**
 * Related Products
 *
 * @author        WooThemes
 * @package       WooCommerce/Templates
 * @version       5.0
 */

if ( !defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

$theme_options_data = theme_options_data();
global $product, $woocommerce_loop;

if ( empty( $product ) || !$product->exists() ) {
	return;
}
$posts_per_page = $theme_options_data['thim_woo_related_product_column'];

$related = wc_get_related_products( $product->get_id(), $posts_per_page );
if ( sizeof( $related ) == 0 ) return;
$args = apply_filters( 'woocommerce_related_products_args', array(
	'post_type'           => 'product',
	'ignore_sticky_posts' => 1,
	'no_found_rows'       => 1,
	'posts_per_page'      => $posts_per_page,
	'orderby'             => $orderby,
	'post__in'            => $related,
	'post__not_in'        => array( $product->get_id() )
) );

$products = new WP_Query( $args );


if ( $products->have_posts() ) : ?>

	<div class="related-products">

		<h3><?php esc_html_e( 'Related Products', 'cakeart' ); ?></h3>

		<ul class="category-product-list row product-grid">

			<?php while ( $products->have_posts() ) : $products->the_post(); ?>

				<?php wc_get_template( 'content-related-product.php' ); ?>

			<?php endwhile; // end of the loop. ?>

		</ul>

	</div>

<?php endif;

wp_reset_postdata();
