I think you would change:
if($skuavailable == 'Yes'){
$gotourl = 'plugins/shopping-cart.php';
}else{
$gotourl = 'products-detail.php?ProductID='.$urlproduct;
};
to:
if($skuavailable == 'Yes'){
$gotourl = 'plugins/shopping-cart.php';
}else{
$gotourl = 'products-detail.php?ProductID='.$urlproduct;
header("location: ".$gotourl);
die();
};
So that it redirects immediately if the item is not in stock before the item is added to the cart.