【发布时间】:2019-07-29 00:37:21
【问题描述】:
我想在我的 WooCommerce 商店中设置最低订单量。如果未达到金额但仍然可以结帐,则以下代码完美显示通知。未达到最低金额时如何禁用结帐按钮?
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
// Set this variable to specify a minimum order value
$minimum = 50;
if ( WC()->cart->total < $minimum ) {
if( is_cart() ) {
wc_print_notice(
sprintf( 'Your current order total is %s — you must have an order with a minimum of %s to place your order ' ,
wc_price( WC()->cart->total ),
wc_price( $minimum )
), 'error'
);
} else {
wc_add_notice(
sprintf( 'Your current order total is %s — you must have an order with a minimum of %s to place your order' ,
wc_price( WC()->cart->total ),
wc_price( $minimum )
), 'error'
);
}
}
}
【问题讨论】:
-
尝试使用
woocommerce_check_cart_items挂钩。
标签: php wordpress woocommerce cart checkout