【发布时间】:2014-11-01 02:20:04
【问题描述】:
我在 Woocommerce 购物车中使用优惠券进行计算。它会自动在总额中添加折扣,以便将正确的金额发送到支付网关。
我想对访问者隐藏有关此优惠券/折扣的所有信息。
问题:我发现的唯一方法(见下文)隐藏了优惠券字段、行(来自总计)和消息,但也禁用了优惠券...
add_filter( 'woocommerce_coupons_enabled', 'hide_coupon_field' );
function hide_coupon_field( $enabled ) {
if ( is_cart() || is_checkout() ) {
$enabled = false;
}
return $enabled;
}
是否有一个钩子可以隐藏与折扣相关的所有内容而不取消优惠券?
编辑: 看起来不可能简单地删除 order-details 中的折扣行。因此,受 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 或get_subtotal_to_display?
【问题讨论】:
-
如果您查看
WC_Order类中的get_item_subtotal()方法,您会发现需要$item参数。
标签: wordpress woocommerce