[英]Woocommerce Minimum Order by User Role
以前有人问过类似我的问题,但是提供的解决方案似乎对我没有帮助。
我正在批发网站上工作。 对于首次购买者,最低订单为500美元。 对于回头买家/重新订购没有最低要求。 我假设我需要担任2个不同的批发用户角色-一个是初次购买者,另一个是退货/重新订购者。 我以为批发新货和批发再订货会行得通。 如何将此应用到functions.php? 这是我当前正在使用的代码:
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'
);
}
}
任何帮助将不胜感激。
您需要current_user_can()
来测试当前用户的操作能力。
首先,您需要为没有任何限制的用户创建一个新角色。 Members插件是用于创建角色和编辑其功能的天才。
例如,您可以创建Returning Wholesaler
角色。
您应该复制“客户”角色的功能...因此, read
, edit_posts
和delete_posts
。
然后,添加一个名为wholesale_reorder
的新功能
然后,您可以将if语句转换为:
if ( WC()->cart->total < $minimum )
至:
if ( WC()->cart->total < $minimum && ! current_user_can( 'wholesale_reorder' ) )
如果您没有任何现有客户,不需要多个级别的批发,不需要与常规客户一起批发, 并且您没有无需订购就可以注册的方法,那么表面上您可以跳过添加新的角色并仅测试current_user_can('customer')
因为唯一会成为客户的人就是那些已经订购了东西的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.