Php购物车问题

时间:2013-04-16 14:24:51

标签: php

我正在尝试修复一个用于wordpress的awm商店插件中的php问题,这可能非常简单,但我的PHP技能并不是最好的,我的解决尝试导致没有成功。

我设置了购物车,以便:

对于居民而言,航运始终免费 非居民的运费为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>

是否有人知道如何设置它以使它在两种情况下都相同?

1 个答案:

答案 0 :(得分:0)

嗯,我想你只需要拿出if Australia的声明吗?

变化

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;
相关问题