【发布时间】:2020-10-18 06:24:35
【问题描述】:
我正在使用来自 Woocommerce Minimum Order Amount 的 sn-p 代码来设置最低订单总额。但我想为每个用户角色设置不同的最小值。
我有一些自定义用户角色:wholesale_prices、wholesale_vat_exc 和 distributor_prices。我想让代码根据每个角色的不同最小数量的使用角色来工作。
这是我的代码:
// Minimum order total
add_action( 'woocommerce_check_cart_items', 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
// Set this variable to specify a minimum order value
$minimum = 300;
if ( WC()->cart->subtotal < $minimum ) {
if( is_cart() ) {
wc_print_notice(
sprintf( 'You must have an order with a minimum 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 an order with a minimum of %s to place your order, your current order total is %s.' ,
wc_price( $minimum ),
wc_price( WC()->cart->subtotal )
), 'error'
);
}
}
【问题讨论】:
-
如果您使用的是预先存在的代码,请在问题中提及来源 - docs.woocommerce.com/document/minimum-order-amount。
-
一年多以前我把那个代码粘贴到我的函数文件中,我真的不记得我从哪里得到它但下次会尽力搜索。
标签: php wordpress woocommerce cart hook-woocommerce