2017-09-05 135 views
1

我嘗試做一件很簡單的事情,但對我來說,我不會讓它工作。根據收費有條件地定製WooCommerce購物車總計總產量

這是從WC-車-的functions.php

 if (! empty($tax_string_array)) { 
      $taxable_address = WC()->customer->get_taxable_address(); 
      $estimated_text = WC()->customer->is_customer_outside_base() && ! WC()->customer->has_calculated_shipping() 
       ? sprintf(' ' . __('estimated for %s', 'woocommerce'), WC()->countries->estimated_for_prefix($taxable_address[0]) . WC()->countries->countries[ $taxable_address[0] ]) 
       : ''; 
      $value .= '<small class="includes_tax">' . sprintf(__('(includes %s)', 'woocommerce'), implode(', ', $tax_string_array) . $estimated_text) . '</small>'; 
     } 
    } 

    echo apply_filters('woocommerce_cart_totals_order_total_html', $value); 
} 

如果施加任何$fee的$值應有所不同。 但我只得到0.00 €值從$fee變量,如果我檢查。

可能有人請幫助我簡單地套用在可變的費用的價值和像一個簡單的if條款檢查:

如果應用費用---> 1
其他---> 2

我該怎麼辦?

回答

0

正如你可以看到你可以使用位於該wc-cart-functions.php核心代碼的woocommerce_cart_totals_order_total_html篩選器掛鉤,以改變盛大的購物車總的輸出:

add_filter('woocommerce_cart_totals_order_total_html', 'custom_cart_totals_order_total_html', 10, 1); 
function custom_cart_totals_order_total_html($value) { 
    // Get the fee cart amount 
    $fees_total = WC()->cart->fee_total; 

    // HERE is the condition 
    if(! empty($fees_total) && $fees_total != 0){ 
     // Change/customize HERE $value (just for test) 
     $value .= " <small>($fees_total)<small>"; 
    } 

    // Always return $value 
    return $value; 
} 

代碼放在的function.php文件您活躍的兒童主題(或主題)或任何插件文件。

該代碼測試和工程。

決不在此改變的核心文件,因爲這是禁止的東西,危險和不方便的原因有很多

您需要自定義條件的代碼$value

+0

Wohoooo! Awsome謝謝你!完美滿足我的需求。只剩下兩個小問題,你救了我的命。我需要將結賬後的概覽以及發送給客戶的電子郵件傳遞給總覽。任何想法如何做的伎倆? ------> 10000000在此先感謝! –

+1

是的,它做到了!非常感謝。但是電子郵件和結賬後呢?你能不能幫助我呢? –

相關問題