1 回答
TA贡献1799条经验 获得超6个赞
使用 WordPress 条件函数,current_user_can()例如:
add_action( 'woocommerce_check_cart_items', 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
// minimum order value by user role
if ( current_user_can('distributor_prices') )
$minimum = 3000;
elseif ( current_user_can('wholesale_prices') )
$minimum = 1000;
elseif ( current_user_can('wholesale_vat_exc') )
$minimum = 600;
else
$minimum = 300; // default
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' );
}
}
}
代码位于活动子主题(或活动主题)的functions.php 文件中。它应该有效。
- 1 回答
- 0 关注
- 103 浏览
添加回答
举报