2016-04-15 29 views
0

我爲WooCommerce創建了一個非常小且簡單的自定義運輸方式,它基本上根據城市和體重計算運費。Woocommerce運輸方式只適用於帳單地址

class WC_Chilexpress_Shipping_Method extends WC_Shipping_Method { 

... 

public function calculate_shipping($package){ 

    $small_price = get_post_meta($shipping[0]->ID, 'chxp_small_price', true); 
    $medium_price = get_post_meta($shipping[0]->ID, 'chxp_medium_price', true); 

    if($weight < 6 && $weight >= 3) : 
     $cost = $medium_price + 1000; 
    elseif($weight < 10 && $weight >= 6) : 
     $cost = $medium_price + 1700; 
    elseif ($weight >= 10) : 
     $cost = $medium_price + 2200; 
    elseif($weight < 3) : 
     $cost = (int)$small_price + 700; 
    endif; 

    $this->add_rate(array(
     'id' => $this->id, 
     'label' => $this->title, 
     'cost' => $cost 
    ));       

    return $cost; 
} 

一切正常,只是使用的帳單地址,但如果是選擇「送貨地址」收銀臺說:「在店內拿起」被選中。

完整的代碼是在這裏:

https://gist.github.com/albertojm/55a9319dadc36c936c84a3904d114fbd

https://gist.github.com/albertojm/8e2e3fe2d90e19dc1875ef04ab565125

+0

你是否使用你的代碼作爲插件?你是否修改了[來自本教程]的代碼(https://waseem-senjer.com/shipping-method-for-woocommerce-development-tutorial/)? – LoicTheAztec

+0

我已經修改了一個類似的代碼(無法記得我找到它的地方)。 – Alberto

回答

0

的問題是,在計算運費後的價格Woocommerce後的數據再發送到結帳頁面,但沒有s_state或狀態後增值稅。

由於我根據這兩個變量計算運費,所以我必須將它們保存到會話變量中並從這裏計算。

相關問題