WordPress 主题开发 WooCommerce 设定最低订单量
WordPress 主题开发 WooCommerce 设定最低订单量,显示一个通知提示客户: /** * …
WordPress 主题开发 WooCommerce 设定最低订单量,显示一个通知提示客户:
-
/**
-
* Set a minimum order amount for checkout
-
*/
-
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
-
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
-
function wc_minimum_order_amount() {
-
https:// 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'
-
);
-
}
-
}
-
}
但未达到最低金额时如何禁用结帐按钮?参考以下:
-
add_action( 'woocommerce_check_cart_items', 'required_min_cart_subtotal_amount' );
-
function required_min_cart_subtotal_amount() {
-
https:// Only run in the Cart or Checkout pages
-
if( is_cart() || is_checkout() ) {
-
https:// HERE Set minimum cart total amount
-
$min_total = 250;
-
https:// Total (before taxes and shipping charges)
-
$total = WC()->cart->subtotal;
-
https:// Add an error notice is cart total is less than the minimum required
-
if( $total <= $min_total ) {
-
https:// Display an error message
-
wc_add_notice( '<strong>' . sprintf( __("A minimum total purchase amount of %s is required to checkout."), wc_price($min_total) ) . '<strong>', 'error' );
-
}
-
}
-
}
将 PHP 代码放在主题或子主题 functions.php 文件的底部。
类别:WordPress教程、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!