$productID = 55437;
print_r(wd_getOptimalPrice($productID, IBLOCK_MAIN_ID));
function wd_getOptimalPrice($productID, $iblock_id = 0)
{
\Bitrix\Main\Loader::includeModule('iblock');
\Bitrix\Main\Loader::includeModule('catalog');
global $USER;
$arPrice = [];
$quantity = 1;
$renewal = 'N';
$arIfSku = CCatalogSKU::getExistOffers($productID, $iblock_id);
if(is_array($arIfSku) && $arIfSku[$productID] === true)
{
$iblock_info = CCatalogSKU::GetInfoByProductIBlock($iblock_id);
if(is_array($iblock_info))
{
$rsOffers = CIBlockElement::GetList(array("PRICE" => "ASC"), array("IBLOCK_ID" => $iblock_info["IBLOCK_ID"], "PROPERTY_" . $iblock_info["SKU_PROPERTY_ID"] => $productID));
$arOffer = $rsOffers->GetNext();
$arPrice = CCatalogProduct::GetOptimalPrice($arOffer['ID'], $quantity, $USER->GetUserGroupArray(), $renewal);
if (!$arPrice || count($arPrice) <= 0)
{
if ($nearestQuantity = CCatalogProduct::GetNearestQuantityPrice($arOffer['ID'], $quantity, $USER->GetUserGroupArray()))
{
$quantity = $nearestQuantity;
$arPrice = CCatalogProduct::GetOptimalPrice($arOffer['ID'], $quantity, $USER->GetUserGroupArray(), $renewal);
}
}
}
} else {
$arPrice = CCatalogProduct::GetOptimalPrice($productID, $quantity, $USER->GetUserGroupArray(), $renewal);
if (!$arPrice || count($arPrice) <= 0)
{
if ($nearestQuantity = CCatalogProduct::GetNearestQuantityPrice($productID, $quantity, $USER->GetUserGroupArray()))
{
$quantity = $nearestQuantity;
$arPrice = CCatalogProduct::GetOptimalPrice($productID, $quantity, $USER->GetUserGroupArray(), $renewal);
}
}
}
return $arPrice;
}