<?php
defined("ABSPATH") || exit();

$cross_sells = array_filter(array_map("wc_get_product", WC()->cart->get_cross_sells()), "wc_products_array_filter_visible");

$cross_sells = wc_products_array_orderby($cross_sells, "rand", "desc");
$cross_sells = array_slice($cross_sells, 0, 4);
$cross_sells_id = uniqid("cart-cross-sell");

if ($cross_sells): ?>
<h2><?php esc_html_e("Mohlo by Vás zaujímať", "inoby")?></h2>
<div id="<?= $cross_sells_id?>" class="cart-cross-sell" data-infinite="1" data-slides="4" data-automatic="1">
  <div class="products">
    <?php foreach ($cross_sells as $cross_sell): ?>
    <?php
        $post_object = get_post($cross_sell->get_id());
        setup_postdata($GLOBALS["post"] = &$post_object);
        wc_get_template_part("content", "product");
        ?>
    <?php endforeach; ?>
    <?php get_template_part("template-parts/keen-arrows", "keen-arrows", ["slider-id" => $cross_sells_id]); ?>
  </div>
</div>
<?php endif;

wp_reset_postdata();