久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

為 Woocommerce 中的特定用戶角色應(yīng)用折扣

Apply a discount for a specific user role in Woocommerce(為 Woocommerce 中的特定用戶角色應(yīng)用折扣)
本文介紹了為 Woocommerce 中的特定用戶角色應(yīng)用折扣的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有一個 woocommerce 商店,有 3 個用戶角色,我想僅為用戶角色公司"提供購物車總額 10% 的折扣.

I have a woocommerce store, with 3 user roles, I want to provide a 10% discount on the cart total only for a user role 'company'.

我發(fā)現(xiàn)"Woocommerce 中基于用戶角色和付款方式的百分比折扣" 答案非常符合我的需要,但不知道如何修改代碼以滿足我的需要,因為它還包含基于付款方式的條件并僅在結(jié)帳時顯示折扣,但我也需要將其顯示在購物車中.

I found "Percentage discount based on user role and payment method in Woocommerce" answer that is very neer of what I need, but don't know how to modify the code to feet my needs, as it contains also a condition based on payment method and displaying the discount only at checkout, but I need it to display in cart as well.

推薦答案

以下代碼將對公司"用戶角色(在購物車和結(jié)帳時)應(yīng)用 10% 的折扣:

The following code will apply a 10% discount for 'company' user role (on cart and checkout):

// Applying conditionally a discount for a specific user role
add_action( 'woocommerce_cart_calculate_fees', 'discount_based_on_user_role', 20, 1 );
function discount_based_on_user_role( $cart ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return; // Exit

    // Only for 'company' user role
    if ( ! current_user_can('company') )
        return; // Exit

    // HERE define the percentage discount
    $percentage = 10;

    $discount = $cart->get_subtotal() * $percentage / 100; // Calculation

    // Applying discount
    $cart->add_fee( sprintf( __("Discount (%s)", "woocommerce"), $percentage . '%'), -$discount, true );
}

代碼位于活動子主題(或活動主題)的 functions.php 文件中.它應(yīng)該有效.

Code goes on functions.php file of your active child theme (or active theme). It should works.

這篇關(guān)于為 Woocommerce 中的特定用戶角色應(yīng)用折扣的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Cannot use #39;Object as class name as it is reserved Cake 2.2.x(不能使用 Object 作為類名,因為它是保留的 Cake 2.2.x)
Session is lost after an OAuth redirect(OAuth 重定向后會話丟失)
Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分頁排序)
CakePHP Shared core for multiple apps(CakePHP 多個應(yīng)用程序的共享核心)
Login [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登錄 [ Auth-identify() ] 始終為 false)
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命錯誤:允許的內(nèi)存大小為 134217728 字節(jié)已用盡(嘗試分配 87 字節(jié)))
主站蜘蛛池模板: 激情视频网站 | 91精品国产91综合久久蜜臀 | 成人三级视频 | 在线精品一区二区 | 成人不卡 | 国产这里只有精品 | 成人在线视频看看 | 欧美福利| 久久久久久久久久一区 | 97国产精品视频 | 天天视频成人 | 特级丰满少妇一级aaaa爱毛片 | 伊人网站在线 | 日韩精品在线看 | 久久在线看| 中文字幕精品一区久久久久 | 亚洲免费一区二区 | 亚洲高清三级 | 狠狠综合网 | 免费在线一区二区三区 | 99免费在线视频 | 黄色播放 | 观看av| 日韩欧美视频在线 | 中文字幕在线观看成人 | 中文字幕高清 | 天天色天天射天天干 | 少妇一区二区三区 | 精品国产一区二区国模嫣然 | 欧美亚洲另类在线 | 亚洲激情在线视频 | 精品国产一级 | 日韩视频中文字幕 | 91人人爽| 九色在线观看 | 欧美精品久久久 | 激情免费视频 | a视频在线 | 国产精品一区二区三 | 午夜色婷婷 | 成人黄色电影免费 |