限制WooCommerce购物车最低付款金额

限制WooCommerce购物车最低付款金额,实现代码如下:
/**
 * Set a minimum order amount for checkout
   source by zuimoban.com
 */
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' 
            );

        }
    }
}

相关文章

  1. 让woocommerce将产品标题设置为产品图片的

    woocommerce图像标题和alt标签对SEO至关重要,更改每个图像标题和alt标签将花费很长时间。一般优化我们会在函数当中加载代码: add_filter(wp_get_attachment_image_attributes, change_attachement_image_a...

    2020-02-29
  2. 阻止恶意URL请求错误查询BBQ脚本代码

    阻止恶意URL请求错误查询BBQ是一个简单的脚本,可保护您的网站免遭恶意URL请求。检查所有传入流量,并悄阻止掉一些恶意请教代码eval(,base64_和过长请求字符串。这是一个简单而可靠...

    2020-04-13
  3. 用户在WooCommerce访问时自动将产品添加到

    实现用户在WooCommerce访问时自动将产品添加到购物车代码: /** * 用户在WooCommerce访问时自动将产品添加到购物车zuimoban.com */add_action( template_redirect, add_product_to_cart );function add_product_to_car...

    2021-07-31
  4. 配置WordPress在Zeus服务器重写规则

    配置WordPress在Zeus服务器重写规则,rewrite.script 如下: RULE_0_START:# get the document rootmap path into SCRATCH:DOCROOT from /# initialize our variablesset SCRATCH:ORIG_URL = %{URL}set SCRATCH:REQUEST_URI = %{URL}# see if th...

    2021-07-31
  5. WooCommerce创建新帐户时通知管理员代码

    WooCommerce创建新帐户时通知管理员代码 /** * Notify admin when a new customer account is created */ add_action( woocommerce_created_customer, woocommerce_created_customer_admin_notification ); function woocommerce_created_custome...

    2021-07-31
  6. 限制WooCommerce购物车最低付款金额

    限制WooCommerce购物车最低付款金额,实现代码如下: /** * Set a minimum order amount for checkout source by zuimoban.com */add_action( woocommerce_checkout_process, wc_minimum_order_amount );add_action( woocommerce_before_ca...

    2021-07-31