我在 Woocommerce 购物车中使用优惠券进行计算。它会自动为总额添加折扣,以便可以将正确的金额发送到支付网关。
我想向访客隐藏有关此优惠券/折扣的所有信息。
Problem:我发现的唯一方法(见下文)隐藏优惠券字段、行(总计)和消息,但也禁用优惠券...
add_filter( 'woocommerce_coupons_enabled', 'hide_coupon_field' );
function hide_coupon_field( $enabled ) {
if ( is_cart() || is_checkout() ) {
$enabled = false;
}
return $enabled;
}
是否有一个钩子可以隐藏与折扣相关的所有内容而不取消优惠券?
EDIT:看起来不可能简单地删除折扣线订单详细信息。因此,受 helgatheviking 建议启发,一个简单的解决方案可能是删除这部分生成的所有总数
<?php if ( $totals = $order->get_order_item_totals() ) foreach ( $totals as $total ) : ?>
<tr>
<th scope="row"><?php echo $total['label']; ?></th>
<td><?php echo $total['value']; ?></td>
</tr>
<?php endforeach; ?>
然后按照我需要的方式一一回应它们。我已经可以用这个显示订单总数
<td><?php echo number_format($order->get_total(),2,'.','')."€"; ?></td>
但现在我正在尝试找回订单小计,以及这段代码
<td><?php echo number_format($order->get_item_subtotal(),2,'.','')."€"; ?></td>
给我一个警告:缺少 WC_Order::get_item_subtotal() 的参数 1。
我不确定是否get_item_subtotal()
是获取订单小计的正确方法。如果是这样,还缺少什么论据?或者我应该四处寻找get_line_subtotal
or get_subtotal_to_display
?