开发者

PHP calculate delivery charges depending on postal code

I'm trying to change some PHP code for an online shop and I having trouble changing a if/elseif part of the code. It should check if the country=x and postal code =y charge s开发者_如何学Goo many euro. There is a else if the country is not X to charge an international rate.

The problem is that is charging every buyer the rate for postal codes included in the elseif declaration :(

if($_SESSION["usuario_alta"]["paisID"]==73)
{
  if($_SESSION["usuario_alta"]["provinciaID"]==24 )
  {
    $_SESSION['compra_gastos_envio'] = 10.50*$_sMULTI;
    echo "10.50&euro; x $_sMULTI = <span><b>".$_SESSION['compra_gastos_envio']."&euro;</b></span>";
  }
  elseif($_SESSION["usuario_alta"]["provinciaID"]==35 || 43)
  {
    $_SESSION['compra_gastos_envio'] = 4.50*$_sMULTI;
    echo "4.50&euro; x $_sMULTI = <span><b>".$_SESSION['compra_gastos_envio']."&euro;</b></span>";
  }
  else
  {
    $_SESSION['compra_gastos_envio'] = 8.50*$_sMULTI;
    echo "8.50&euro; x $_sMULTI = <span><b>".$_SESSION['compra_gastos_envio']."&euro;</b></span>";
  }
}
else
{
  $_SESSION['compra_gastos_envio'] = str_replace(",",".",$_SESSION["usuario_alta"]["gastos"])*$_sMULTI;
  echo $_SESSION["usuario_alta"]["gastos"]." x $_sMULTI = <span><b>".$_SESSION['compra_gastos_envio']."&euro;</b></span>";
}

I'm quite sure the answer is trivial, but I have been trying to google for a solution with no success for a while now.

Thanks!


elseif ($_SESSION["usuario_alta"]["provinciaID"] == 35 || 43)

This doesn't work, you can't compare to two values at once. Write it like:

elseif ($_SESSION["usuario_alta"]["provinciaID"] == 35 || $_SESSION["usuario_alta"]["provinciaID"] == 43)

or

elseif (in_array($_SESSION["usuario_alta"]["provinciaID"], array(35, 43)))


I think the problem is this line:

} elseif($_SESSION["usuario_alta"]["provinciaID"]==35 || 43){

This resolves to if $_SESSION[][] is equal to 35 OR if 43. Since 43 is greater than 0, 43 evaluates to true, which will cause the elseif to always be executed unless the preceeding if condition was true.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜