Я пытаюсь исправить проблему с 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, и мне нужно то же правило, которое распространяется на каждую другую страну, чтобы подать заявку на аштралиан. Так что если он составляет <500, он начисляет сумму, и если его> 500, он заряжает $ 0. Дайте мне знать, если это не ясно! – Ciaran
Ну, тогда вы, вероятно, умножаете итог на стоимость доставки - не так ли? –