2017-09-05 139 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

是的,它做到了!非常感谢。但是电子邮件和结账后呢?你能不能帮助我呢? –

相关问题