【发布时间】:2017-08-17 14:32:52
【问题描述】:
是否有任何 woocommerce 挂钩/方法可以让我从购物车总额中排除运费?
我到处搜索,但似乎找不到答案。
【问题讨论】:
标签: php wordpress woocommerce cart shipping
是否有任何 woocommerce 挂钩/方法可以让我从购物车总额中排除运费?
我到处搜索,但似乎找不到答案。
【问题讨论】:
标签: php wordpress woocommerce cart shipping
使用挂在 woocommerce_calculate_totals 动作钩子中的自定义函数,您将从购物车总数中排除运费(仅显示在购物车页面中): p>
// 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;
}
代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件中。
经过测试并且可以工作……
【讨论】:
&& is_cart()...