【发布时间】:2021-12-13 12:30:39
【问题描述】:
我正在尝试从购物车总数中删除运费,我已使用以下代码在购物车和结帐页面上进行处理。
但是,在“订单确认”页面上,配送并未被删除。
为购物车和结帐工作
add_action( 'woocommerce_after_calculate_totals', 'woocommerce_after_calculate_totals', 110 );
function woocommerce_after_calculate_totals( $cart ) {
// make magic happen here...
// use $cart object to set or calculate anything.
## Get The shipping totals
$shipping = WC()->cart->get_shipping_total();
$totalincshipping = $cart->total;
$cart->total = $totalincshipping-$shipping;
}
我在 ORDER CONFIRMATION 页面尝试了以下操作,但这并没有得到预期的结果:
add_action( 'woocommerce_checkout_create_order', 'change_total_on_checking', 100, 2 );
function change_total_on_checking( $order ) {
// Get order total
$shipping = $order->get_shipping_total();
$total = $order->get_total();
## -- Make your checking and calculations -- ##
$new_total = $total - "10"; // <== Fake calculation
// Set the new calculated total
$order->set_total( $new_total );
}
有什么建议吗?
【问题讨论】:
-
是“收到订单”页面吗?
-
@bossman 是的
标签: wordpress woocommerce cart orders shipping