[英]Woocommerce Minimum Order by User Role
Somebody previously asked a question similar to mine, but the solutions offered do not seem to help me. 以前有人问过类似我的问题,但是提供的解决方案似乎对我没有帮助。
I am working on a wholesale website. 我正在批发网站上工作。 For first time buyers, the minimum order is $500.
对于首次购买者,最低订单为500美元。 For returning buyers / reorders there is no minimum.
对于回头买家/重新订购没有最低要求。 I am assuming I need to make 2 different wholesale user roles - one for first time buyers and the other for returning / reorder buyers.
我假设我需要担任2个不同的批发用户角色-一个是初次购买者,另一个是退货/重新订购者。 I was thinking Wholesale New and Wholesale Reorder would work.
我以为批发新货和批发再订货会行得通。 How do I apply this to the functions.php?
如何将此应用到functions.php? This is the code I am currently using:
这是我当前正在使用的代码:
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
// Set this variable to specify a minimum order value
$minimum = 500;
if ( WC()->cart->total < $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->total )
), '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->total )
), 'error'
);
}
}
Any help would be greatly appreciated. 任何帮助将不胜感激。
You need current_user_can()
to test the current user's capability to do something. 您需要
current_user_can()
来测试当前用户的操作能力。
First, you would need to create a new role for users who don't have any restrictions. 首先,您需要为没有任何限制的用户创建一个新角色。 The Members plugin is genius for creating roles and editing their capabilities.
Members插件是用于创建角色和编辑其功能的天才。
For example, you could create a Returning Wholesaler
role. 例如,您可以创建
Returning Wholesaler
角色。
You should duplicate the "Customer" role's capabilities... so read
, edit_posts
, and delete_posts
. 您应该复制“客户”角色的功能...因此,
read
, edit_posts
和delete_posts
。
And then, add a new capability called wholesale_reorder
然后,添加一个名为
wholesale_reorder
的新功能
Then you can convert your if statement from: 然后,您可以将if语句转换为:
if ( WC()->cart->total < $minimum )
to: 至:
if ( WC()->cart->total < $minimum && ! current_user_can( 'wholesale_reorder' ) )
If you don't have any existing customers, don't need multiple levels of wholesale, don't have wholesale in conjunction with regular customers, and you don't have a way to register without ordering, then ostensibly you could skip adding new roles and just test current_user_can('customer')
as the only people who would be customers would be those who have ordered something already. 如果您没有任何现有客户,不需要多个级别的批发,不需要与常规客户一起批发, 并且您没有无需订购就可以注册的方法,那么表面上您可以跳过添加新的角色并仅测试
current_user_can('customer')
因为唯一会成为客户的人就是那些已经订购了东西的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.