2013-04-16 100 views
0

我正在尝试修复一个awm商店插件中的php问题,它可能是非常直接的,但是我的PHP技能并不是最好的,而我的解决方案尝试导致没有成功。Php购物车问题

我有购物车设置,以便:

航运是永远免费AUS居民 航运是对非居民$ 15,但是免费的,如果他们为了> $ 500强

用下面的代码:

foreach($cart_items as $items) { 
     if($items['type'] == "purchase") { 
      $amount = $amount + ($items['price'] * $items['quantity']); 
     }else{ 
      $amount = $amount + ($items['price'] * $items['quantity']); 
     } 
    } 

    $country = ""; 

    if($order_details['billing_not_shipping']){ 
     $country = $order_details['shipping_country']; 
    }else{ 
     $country = $order_details['billing_country']; 
    } 

    if(strtolower($country) == "australia") 
    { 
     $this_quote = $simple_shipping_options[1]['order_fee']; 
     foreach($cart_items as $cart_item){ 
      $this_quote += $cart_item['quantity'] * $simple_shipping_option['product_fee']; 
     } 
     $return_quotes[] = array(
      'name' => $simple_shipping_options[1]['name'], 
      'total' => $this_quote, 
     ); 
    } 
    else 
    { 
     if($amount > 500) { 
      $this_quote = $simple_shipping_options[0]['order_fee']; 
      foreach($cart_items as $cart_item){ 
       $this_quote += $cart_item['quantity'] * $simple_shipping_option['product_fee']; 
      } 
      $return_quotes[] = array(
       'name' => "Free Shipping for any order over $500", 
       'total' => $this_quote, 
      ); 
     }else{ 
      $this_quote = $simple_shipping_options[1]['order_fee']; 
      foreach($cart_items as $cart_item){ 
       $this_quote += $cart_item['quantity'] * $simple_shipping_option['product_fee']; 
      } 
      $return_quotes[] = array(
       'name' => $simple_shipping_options[1]['name'], 
       'total' => $this_quote, 
      ); 
     } 
    } 

    return $return_quotes; 
} 

而且

<table class="form-table awms_settings_shipping_simple"> 
<tr> 
    <td scope="row"><label for="aus_residents">Free Shipping within Australia</label></td> 
    <td><input name="shipping_custom_order_fee[]" type="text" id="aus_residents" value="<?php echo $shipping_custom[1]["order_fee"] ?>" />$ AUD</td> 
    <input type="hidden" name="shipping_custom_name[]" value="Free shipping within Australia" /> 
</tr> 
<tr> 
    <td scope="row"><label for="aus_not_residents">Outside Australia</label></td> 
    <td><input name="shipping_custom_order_fee[]" type="text" id="aus_not_residents" value="<?php echo $shipping_custom[1]["order_fee"]; ?>" /> $ AUD</td> 
    <input type="hidden" name="shipping_custom_name[]" value="Outside Australia" /> 
</tr> 

有谁知道如何设置它,使它在两种情况下都是一样的?

+0

你的逻辑看起来是正确的。你有什么问题? –

+0

它适用于除澳大利亚以外的所有国家。对于澳大利亚,它总是免费的,即$ 0,我需要适用于其他所有国家也适用于中立人的相同规则。因此,如果它的价格低于500美元,并且价格高于500美元,则价格为0美元。让我知道如果它不明确! – Ciaran

+0

那么,你可能会乘以运费 - 你呢? –

回答

0

嗯我认为你只需要采取如果澳大利亚的声明呢?

变化

if(strtolower($country) == "australia")

if(strtolower($country) == "australiaX")

要忽略声明..或

/* if(strtolower($country) == "australia") 
    { 
     $this_quote = $simple_shipping_options[1]['order_fee']; 
     foreach($cart_items as $cart_item){ 
      $this_quote += $cart_item['quantity'] * $simple_shipping_option['product_fee']; 
     } 
     $return_quotes[] = array(
      'name' => $simple_shipping_options[1]['name'], 
      'total' => $this_quote, 
     ); 
    } 
    else 
    { 
*/ 
     if($amount > 500) { 
      $this_quote = $simple_shipping_options[0]['order_fee']; 
      foreach($cart_items as $cart_item){ 
       $this_quote += $cart_item['quantity'] * $simple_shipping_option['product_fee']; 
      } 
      $return_quotes[] = array(
       'name' => "Free Shipping for any order over $500", 
       'total' => $this_quote, 
      ); 
     }else{ 
      $this_quote = $simple_shipping_options[1]['order_fee']; 
      foreach($cart_items as $cart_item){ 
       $this_quote += $cart_item['quantity'] * $simple_shipping_option['product_fee']; 
      } 
      $return_quotes[] = array(
       'name' => $simple_shipping_options[1]['name'], 
       'total' => $this_quote, 
      ); 
     } 
/* }*/ 

    return $return_quotes; 
+0

我试过了,但它似乎仍然是免费送货到澳大利亚。我会添加表单,它允许我在wordpress中更改发货量,但是我也尝试过编辑这个表单,我没有任何喜悦。感谢您的帮助! – Ciaran

+0

'print_r($ simple_shipping_options)'的输出是什么;' –

+0

它似乎打破了整个购物车,当我出于某种原因实际上评论了一下。感谢您的建议,但我认为这样做也是。 – Ciaran