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 關注
- 136 瀏覽
添加回答
舉報