<?php

function inoby_add_upsell_products($product, $cart_item) {
  if (is_a($product, 'WC_Product_Variation')) {
    $parentProduct = wc_get_product( $product->get_parent_id() );
    $upsells = $parentProduct->get_upsell_ids();
  } else {
    $upsells = $product->get_upsell_ids();
  }
  if ($upsells) { ?>
      <?= get_template_part("woocommerce/cart/cart-item-upsell", null, ["product" => $product, "cart_item" => $cart_item, "upsells" => $upsells]) ?>
    <?php }
}

if (ESHOP_ENABLED && Inoby_Config::show_cart_upsells()) {
  add_action("rc_cart_item_after", "inoby_add_upsell_products", 10, 2);
}
