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

在 Woocommerce 中僅顯示特定客戶所在國家/地區的價

Show prices only for a specific customer#39;s country in Woocommerce(在 Woocommerce 中僅顯示特定客戶所在國家/地區的價格)
本文介紹了在 Woocommerce 中僅顯示特定客戶所在國家/地區的價格的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我已經使用 woocommerce 開發了一個目錄,但是由于我無法控制的原因,我需要能夠對從英國以外訪問該網站的用戶隱藏產品價格.

我找到了允許我根據訪問者位置更改產品價格的插件,但沒有任何東西可以讓我隱藏價格.

是否有我遺漏的插件或我可以添加到 woocommerce 文件中以實現此目的的任何內容?

解決方案

以下內容將隱藏英國以外的價格,基于客戶地理定位的國家:

add_filter( 'woocommerce_get_price_html', 'country_geolocated_based_hide_price', 10, 2 );函數 country_geolocated_based_hide_price( $price, $product ) {//獲取 WC_Geolocation 對象類的實例$geo_instance = new WC_Geolocation();//獲取地理定位的用戶地理數據.$user_geodata = $geo_instance->geolocate_ip();//獲取當前用戶的 GeoIP 國家$country = $user_geodata['country'];返回 $country !== 'GB' ?'' : $價格;}

代碼位于活動子主題(或活動主題)的 function.php 文件中.經測試有效.

<小時>

如果您只想為未登錄的客戶啟用該地理定位功能,請使用以下命令:

add_filter( 'woocommerce_get_price_html', 'country_geolocated_based_hide_price', 10, 2 );函數 country_geolocated_based_hide_price( $price, $product ) {如果(get_current_user_id()> 0){$country = WC()->customer->get_billing_country();} 別的 {//獲取 WC_Geolocation 對象類的實例$geo_instance = new WC_Geolocation();//獲取地理定位的用戶地理數據.$user_geodata = $geo_instance->geolocate_ip();//獲取當前用戶的 GeoIP 國家$country = $user_geodata['country'];}返回 $country !== 'GB' ?'' : $價格;}

<塊引用>

此代碼的更新版本在此答案上可用,避免了后端錯誤.

我在開始時添加了函數:

if ( is admin() ) return $price;

代碼位于活動子主題(或活動主題)的 function.php 文件中.經測試有效.

I've developed a catalogue using woocommerce, however I need to be able to hide product prices from users who are visiting the site from outside of the UK due to reasons outside of my control.

I've found plugins that allow me to change product prices based on visitor location, but nothing allows me to hide the prices.

Is there any plugins that I've missed or anything I can add in to the woocommerce files to achieve this?

解決方案

The following will hide prices outside United kingdom based on customer geolocated country:

add_filter( 'woocommerce_get_price_html', 'country_geolocated_based_hide_price', 10, 2 );
function country_geolocated_based_hide_price( $price, $product ) {
    // Get an instance of the WC_Geolocation object class
    $geo_instance  = new WC_Geolocation();
    // Get geolocated user geo data.
    $user_geodata = $geo_instance->geolocate_ip();
    // Get current user GeoIP Country
    $country = $user_geodata['country'];

    return $country !== 'GB' ? '' : $price;
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.


If you want to enable that geolocated feature only for unlogged customers, use the following:

add_filter( 'woocommerce_get_price_html', 'country_geolocated_based_hide_price', 10, 2 );
function country_geolocated_based_hide_price( $price, $product ) {
    if( get_current_user_id() > 0 ) {
        $country = WC()->customer->get_billing_country();
    } else {
        // Get an instance of the WC_Geolocation object class
        $geo_instance  = new WC_Geolocation();
        // Get geolocated user geo data.
        $user_geodata = $geo_instance->geolocate_ip();
        // Get current user GeoIP Country
        $country = $user_geodata['country'];
    }
    return $country !== 'GB' ? '' : $price;
}

An updated version of this code is available on this answer avoiding a backend bug.

I have added in the function on start:

if ( is admin() ) return $price;

Code goes in function.php file of your active child theme (or active theme). Tested and works.

這篇關于在 Woocommerce 中僅顯示特定客戶所在國家/地區的價格的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 字節))
主站蜘蛛池模板: 在线91 | 97人人澡人人爽91综合色 | 欧美日韩亚洲国产 | 日韩三区在线 | 成人在线精品视频 | 欧美日韩国产高清视频 | 一区二区三区四区在线视频 | 二区av| 成人天堂噜噜噜 | 伦理午夜电影免费观看 | 欧洲一区视频 | 亚洲欧美日韩中文字幕一区二区三区 | 不卡一区| 一区二区三区精品视频 | 天天看天天干 | 亚洲综合区| 亚洲自拍偷拍免费视频 | 91日b| 日韩精品在线视频免费观看 | 成人高清在线视频 | 日韩一区二区三区av | 欧美日韩精品 | 亚洲精品高清视频在线观看 | 欧美精品乱码99久久影院 | 精品一区二区三区在线观看 | 精品在线99 | 亚洲va欧美va天堂v国产综合 | 国产亚洲精品久久久久久牛牛 | 精品综合 | 国产精品美女久久久久久不卡 | www久久久 | 精品真实国产乱文在线 | 久久精品一区 | 国产欧美精品一区二区色综合 | 欧美一区二区在线 | 天天爱天天操 | 中文在线www | 婷婷综合色 | 亚洲免费人成在线视频观看 | 久久综合久久久 | 国产精品美女www爽爽爽视频 |