2013-04-16 2 views
0

Я пытаюсь исправить проблему с php в плагине awm для Wordpress, который, вероятно, довольно прямолинейный, но мои навыки PHP не самые лучшие, и мои попытки решения не привели к успеху.Php Shopping Cart Issue

У меня есть корзина настроить так, что:

доставка всегда бесплатно для жителей 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

Смежные вопросы