2016-08-31 79 views
2

我正在使用WooCommerce和Paid Memberships Pro free pluginWooCommerce - 爲免費用戶計劃添加運費

在網站上我們有2個計劃(自由計劃和支付計劃):

  • 免費用戶可以購買每月1項,
  • 付費用戶可以購買4項各月。

現在我不知道如何簡單地計算運費結帳頁面上有類似的代碼:

if (pmpro_hasMembershipLevel('2')) { // Paid plan 

    //free shipping (0$) 

} else { 

    //add shipping 4$ to checkout 

} 

沒有運輸類,沒有一個地區區域是影響航運價格。

我試圖設置運輸選項,但我無法擺脫它。

我該如何做到這一點?

謝謝。

回答

3

由於WooCommerce 2.6+版本的出貨已經過重新設計,並且根據需要自定義它非常複雜,沒有插件...取而代之的是,根據用戶級別和其他條件添加費用(如果需要)。

這裏是我的代碼:

function add_shipping_fee() { 

    // Set here your shipping fee amount 
    $fee = 4; 

    if (is_admin() && ! defined('DOING_AJAX')) 
     return; 

    if (pmpro_hasMembershipLevel('2') == false) 
     WC()->cart->add_fee(__('Shipping Fee:', 'your_theme_slug'), $fee, false); 
} 
add_action('woocommerce_cart_calculate_fees','add_shipping_fee'); 

這自然會去你的活動的子主題(或主題)的function.php文件或也以任何插件文件。

此代碼已經過測試和工作。


參考文獻:

+0

你是真棒! – Amino