在Woocommerce购物车页面上从购物车总计中排除运输费用
答
使用woocommerce_calculate_totals
动作钩子钩住这个自定义函数,你会从车总计(只是在购物车页面显示)中排除运费:
// For WooCommerce versions from 2.5.x up to 3+
add_action('woocommerce_calculate_totals', 'custom_cart_displayed_totals', 10, 1);
function custom_cart_displayed_totals($cart_object) {
if (is_admin() && ! defined('DOING_AJAX'))
return;
// Only on cart page
if (! WC()->cart->is_empty() && is_cart()):
## Get The shipping totals
$shipping_tax_amount = $cart_object->shipping_total;
$shipping_total_excl_tax = $cart_object->shipping_tax_total;
## Displayed subtotal
// $cart_object->subtotal = 0;
## Displayed TOTAL
// $cart_object->total = 0;
## Displayed TOTAL
$cart_object->tax_total -= $shipping_tax_amount;
## Displayed TOTAL
$cart_object->cart_contents_total -= $shipping_total_excl_tax;
endif;
}
代码放在功能。你的活动儿童主题(或主题)的php文件或任何插件文件。
测试和工作...