简体   繁体   English

Woocommerce最低订单(按用户角色)

[英]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()来测试当前用户的操作能力。

Create a Role 创建角色

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角色。

Define the new Role's capabilities 定义新角色的功能

You should duplicate the "Customer" role's capabilities... so read , edit_posts , and delete_posts . 您应该复制“客户”角色的功能...因此, readedit_postsdelete_posts

And then, add a new capability called wholesale_reorder 然后,添加一个名为wholesale_reorder的新功能

Modify your conditional logic 修改您的条件逻辑

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' ) )

Simplification in the case of no new roles 没有新角色时进行简化

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.

相关问题 Woocommerce 为特定用户角色设置最低订单 - Woocommerce set minimum order for a specific user role 通过用户角色和订单历史在 WooCommerce 中设置最小订单量 - Set minimum order amount in WooCommerce by user role and order history WooCommerce中基于用户角色和类别的最小数量订购规则 - Minimum quantity order rules in WooCommerce based on user role and categories WooCommerce:在完成一定数量的订单或单笔订单达到最低金额后自动更改用户角色 - WooCommerce: Automatically change the user role after a certain quantity of completed orders or a minimum amount in one order Woocommerce 基于用户角色的最小订单总数 - Woocommerce minimum order total based on user roles 为WooCommerce创建订单状态验证的用户角色 - Create an user role for order status validation on WooCommerce 防止用户角色更改 woocommerce 订单状态 - Prevent User Role from changing woocommerce order status 在 Woocommerce 中为特定用户角色设置最小订单量 - Set a minimal order amount for a specific User role in Woocommerce 使用 WooCommerce 订单转换状态挂钩添加用户角色 - Add a user role using WooCommerce order transition status hooks Woocommerce中订单状态完成后保留自定义用户角色 - Keep custom user role after order status is completed in Woocommerce
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM