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

以編程方式為特定用戶角色禁用稅收

Disable tax programmatically for a specific user role(以編程方式為特定用戶角色禁用稅收)
本文介紹了以編程方式為特定用戶角色禁用稅收的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

在我的 woocommerce 網站中,我在 WooCommerce 的一般設置中啟用了稅.

我想以編程方式(使用任何鉤子)從我的商店、結帳頁面和訂單電子郵件中禁用特定用戶角色的稅收.

我怎樣才能做到這一點?

謝謝

解決方案

2020 更新

<塊引用>

您不能以編程方式為特定用戶角色禁用 WooCommerce 稅,但您可以為特定用戶角色申請零稅率.

首先您需要在 worpress 中設置這個特定的用戶角色.如果是這種情況,假設此自定義用戶角色是我的代碼示例的 'resellers'.

其次,您必須在 WooCommerce 設置中啟用零稅率:

然后對于每個國家/地區,您必須設置此零稅率:

第三 - 然后這個鉤子函數會起作用:

更新 - 從 WooCommerce 3 開始使用以下內容:

函數 zero_rate_for_custom_user_role( $tax_class, $product ) {//獲取當前用戶$current_user = wp_get_current_user();$current_user_data = get_userdata($current_user->ID);//<== <== <== <== <== <== <== 在這里放置您的用戶角色 slugif ( in_array( 'resellers', $current_user_data->roles ) )$tax_class = '零稅率';返回 $tax_class;}add_filter('woocommerce_product_get_tax_class', 'wc_diff_rate_for_user', 10, 2);add_filter('woocommerce_product_variation_get_tax_class', 'wc_diff_rate_for_user', 10, 2);

在 WooCommerce 版本 3 之前使用以下內容:

函數 zero_rate_for_custom_user_role( $tax_class, $product ) {//獲取當前用戶$current_user = wp_get_current_user();$current_user_data = get_userdata($current_user->ID);//<== <== <== <== <== <== <== 在這里放置您的用戶角色 slugif ( in_array( 'resellers', $current_user_data->roles ) )$tax_class = '零稅率';返回 $tax_class;}add_filter('woocommerce_product_tax_class', 'zero_rate_for_custom_user_role', 10, 2 );

<塊引用>

您只需要輸入您想要的用戶角色而不是經銷商".

此代碼位于活動子主題(或主題)的 functions.php 文件或任何插件文件中.

此代碼經過測試且功能齊全.

參考:WooCommerce- 啟用零利率";某些特定用戶角色的稅級

In my woocommerce web site, I have enable Tax in general WooCommerce settings.

I would like to disable tax for a specific user role programmatically ( with any hooks ), from my shop, checkout page and from order email.

How could I achieve this?

Thanks

解決方案

2020 update

You can't disable WooCommerce tax for a specific user role programmatically, but you can apply for a specific user role a zero tax rate.

First you need to have this specific user role set in worpress. If it's the case, let say that this custom user role is 'resellers' for my code example.

Second, you have to enable in WooCommerce settings a zero tax rate:

And then for each country, you will have to set this zero tax rate:

Third - Then this hooked function will do the trick:

Update - Since WooCommerce 3 use the following:

function zero_rate_for_custom_user_role( $tax_class, $product ) {
    // Getting the current user 
    $current_user = wp_get_current_user();
    $current_user_data = get_userdata($current_user->ID);
    
    //  <== <== <== <== <== <== <== Here you put your user role slug 
    if ( in_array( 'resellers', $current_user_data->roles ) )
        $tax_class = 'Zero Rate';

    return $tax_class;
}
add_filter( 'woocommerce_product_get_tax_class', 'wc_diff_rate_for_user', 10, 2 );
add_filter( 'woocommerce_product_variation_get_tax_class', 'wc_diff_rate_for_user', 10, 2 );

Before WooCommerce version 3 use the following:

function zero_rate_for_custom_user_role( $tax_class, $product ) {
    // Getting the current user 
    $current_user = wp_get_current_user();
    $current_user_data = get_userdata($current_user->ID);
    
    //  <== <== <== <== <== <== <== Here you put your user role slug 
    if ( in_array( 'resellers', $current_user_data->roles ) )
        $tax_class = 'Zero Rate';

    return $tax_class;
}
add_filter( 'woocommerce_product_tax_class', 'zero_rate_for_custom_user_role', 10, 2 );

You will just need to put instead of 'resellers' your desired user role slug.

This code goes in functions.php file of your active child theme (or theme) or also in any plugin file.

This code is tested and fully functional.

Reference: WooCommerce - Enabling "Zero rate" tax class to some specific user roles

這篇關于以編程方式為特定用戶角色禁用稅收的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

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 多個應用程序的共享核心)
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)(致命錯誤:允許的內存大小為 134217728 字節已用盡(嘗試分配 87 字節))
主站蜘蛛池模板: 亚洲精品国产综合区久久久久久久 | 国产激情免费视频 | 超碰97人人人人人蜜桃 | 国产欧美日韩精品在线观看 | 亚洲91精品 | 国产在线视频一区二区 | 欧美一区二区 | 国产精品视屏 | 国产精品视频网 | 午夜免费精品视频 | 精品久久成人 | 日韩在线精品视频 | 天堂va在线观看 | 久久69精品久久久久久久电影好 | 91影院在线观看 | 成人高清视频在线观看 | 精品综合久久久 | 久久亚洲国产 | 日韩中文字幕高清 | 国产精品亚洲精品 | www.操.com| 久草在线在线精品观看 | 99re热精品视频 | 91高清在线观看 | 色资源站 | 精品一区二区三区免费毛片 | 青娱乐av| 91精品一区二区三区久久久久 | 在线视频91| 天天操天天摸天天爽 | 亚洲午夜精品在线观看 | 成人高清在线 | 中文字幕免费在线 | 久久国产99 | 国产精品观看 | 在线亚洲免费 | 亚洲伊人久久综合 | 91精品国产色综合久久 | 国产美女视频 | 国产高清精品在线 | 99久久精品国产一区二区三区 |