【发布时间】:2017-08-18 16:47:10
【问题描述】:
我需要在购物车中设置最低订单费用,因此如果购物车中的产品总额不超过 10 英镑,则需要支付额外费用以将价格提高到 10 英镑。
这是我目前拥有的代码,它在购物车阶段运行良好,但是当您到达结帐时,定价部分由于某种原因不会停止加载并且您无法结帐,有人可以帮忙吗?
functions.php 中的代码:
function woocommerce_custom_surcharge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$minimumprice = 10;
$currentprice = $woocommerce->cart->cart_contents_total;
$additionalfee = $minimumprice - $currentprice;
if ( $additionalfee >= 0 ) {
wc_print_notice(
sprintf( 'We have a minimum %s per order. As your current order is only %s, an additional fee will be applied at checkout.' ,
wc_price( $minimumprice ),
wc_price( $currentprice )
), 'error'
);
$woocommerce->cart->add_fee( 'Minimum Order Adjustment', $additionalfee, true, '' );
}
}
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
【问题讨论】:
标签: php wordpress woocommerce checkout cart