View Categories

WooCommerce:定义最低订单金额

< 1 min read

今天我们来看看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' );
  
        }
 
    }
  
}