预计阅读时间: 4 分钟

今天我们来看看WooCommerce的最低订单金额。如果订单低于设置的阈值,此代码段将在购物车页面上显示错误通知,并显示一条错误消息@ Checkout Process。


add_action( 'woocommerce_checkout_process', 'bbloomer_wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart', 'bbloomer_wc_minimum_order_amount' );
   
function bbloomer_wc_minimum_order_amount() {
      
    $minimum = 25; // change this to your minimum order amount
  
    if ( WC()->cart->subtotal < $minimum ) {
  
        if ( is_cart() ) {
  
            wc_print_notice( 
                sprintf( 'You must have a minimum order amount of %s to place your order. Your current order total is %s.' , wc_price( $minimum ), wc_price( WC()->cart->subtotal ) ), 'error' );
  
        } else {
  
            wc_add_notice( 
                sprintf( 'You must have a minimum order amount of %s to place your order. Your current order total is %s.' , wc_price( $minimum ), wc_price( WC()->cart->subtotal ) ), 'error' );
  
        }
 
    }
  
}
此文章对你有帮助吗? 已有 0 人说这篇文章是有用的。