您好StackOverflow成员,希望您一切都好。
我看到了几个关于woocommerce中每个角色的最小数量的问题。 在我的情况下,我想添加一个条件,我希望每个角色的数量最少,但仅针对第一订单,然后他们才能以某种方式完成自己想做的事情
我在这里询问的第一部分中看到了这个作品,但是我该如何添加我的第二个条件:仅在第一顺序上?
// Cart and checkout validation
add_action( 'woocommerce_check_cart_items', 'minimal_total_required' ); // Cart and Checkout
add_action( 'woocommerce_checkout_process', 'minimal_total_required' ); // Checkout (optional)
function minimal_total_required() {
$user = wp_get_current_user();
## -- YOUR SETTINGS BELOW -- ##
$min_amount = 50; // Minimal order amount
$targeted_role = 'wholesale_buyer'; // User role
// Exit for non logged users or when minimal order amout is reached
if( $user->ID == 0 || WC()->cart->subtotal >= $min_amount )
return;
// Display an error notice for Wholesale user role
if ( in_array( $targeted_role, $user->roles ) )
wc_add_notice( sprintf( __("As a Wholesale user you must have a minimal order total of %s.") , wc_price($min_amount) ), 'error' );
}