簡體   English   中英

Woocommerce最低訂單(按用戶角色)

[英]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角色。

定義新角色的功能

您應該復制“客戶”角色的功能...因此, readedit_postsdelete_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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM