WordPress教程

WordPress 主题开发 WooCommerce 设定最低订单量

阿里云

WordPress 主题开发 WooCommerce 设定最低订单量,显示一个通知提示客户:

  1.     /**
  2.      * Set a minimum order amount for checkout
  3.      */
  4.     add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
  5.     add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
  6.  
  7.     function wc_minimum_order_amount() {
  8.         https:// Set this variable to specify a minimum order value
  9.         $minimum = 50;
  10.  
  11.         if ( WC()->cart->total < $minimum ) {
  12.  
  13.             if( is_cart() ) {
  14.  
  15.                 wc_print_notice( 
  16.                     sprintf( 'Your current order total is %s — you must have an order with a minimum of %s to place your order ' , 
  17.                         wc_price( WC()->cart->total ), 
  18.                         wc_price( $minimum )
  19.                     ), 'error' 
  20.                 );
  21.  
  22.             } else {
  23.  
  24.                 wc_add_notice( 
  25.                     sprintf( 'Your current order total is %s — you must have an order with a minimum of %s to place your order' , 
  26.                         wc_price( WC()->cart->total ), 
  27.                         wc_price( $minimum )
  28.                     ), 'error' 
  29.                 );
  30.  
  31.             }
  32.         }
  33.     }
也想出现在这里?联系我们
创客主机

但未达到最低金额时如何禁用结帐按钮?参考以下:

  1.     add_action( 'woocommerce_check_cart_items', 'required_min_cart_subtotal_amount' );
  2.     function required_min_cart_subtotal_amount() {
  3.         https:// Only run in the Cart or Checkout pages
  4.         if( is_cart() || is_checkout() ) {
  5.  
  6.             https:// HERE Set minimum cart total amount
  7.             $min_total = 250;
  8.  
  9.             https:// Total (before taxes and shipping charges)
  10.             $total = WC()->cart->subtotal;
  11.  
  12.             https:// Add an error notice is cart total is less than the minimum required
  13.             if( $total <= $min_total  ) {
  14.                 https:// Display an error message
  15.                 wc_add_notice( '<strong>' . sprintf( __("A minimum total purchase amount of %s is required to checkout."), wc_price($min_total) ) . '<strong>', 'error' );
  16.             }
  17.         }
  18.     }

将 PHP 代码放在主题或子主题 functions.php 文件的底部。

WordPress 主题开发 WooCommerce 设定最低订单量

已有 283 人购买
查看演示升级 VIP立刻购买

收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!