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

在 Woocommerce 中顯示基于客戶送貨區域的自定義消

Display a custom message based on customer shipping zone in Woocommerce(在 Woocommerce 中顯示基于客戶送貨區域的自定義消息)
本文介紹了在 Woocommerce 中顯示基于客戶送貨區域的自定義消息的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

在 woocommerce 中,我需要根據送貨區域在購物車或結帳頁面上顯示自定義消息,例如您將為此郵政編碼多支付 10% 的費用".

In woocommerce, I need to display custom message on cart or checkout page, based on shipping zone, like "you'll be charged 10% more for this zip code".

我覺得這很容易,但我不能讓它工作!它讓我發瘋!任何幫助表示贊賞.

I feel its easy but I can't get it work ! And its drive me crazy! Any help is appreciated.

我的解決方法是自定義那種默認消息:

My workaround is about customizing that kind of default message :

add_filter( 'woocommerce_no_shipping_available_html', 'wf_customize_default_message', 10, 1 );
// For Checkout page
add_filter( 'woocommerce_cart_no_shipping_available_html', 'wf_customize_default_message', 10, 1 );
function wf_customize_default_message( $default_msg ) {
    $zip_array = array(
        '30031',
    );

    if ( in_array( WC()->customer->get_shipping_postcode() , $zip_array) ) {
        $custom_msg = "Call us for quotation - 1-800-XXX-XXXX";
        if( empty( $custom_msg ) ) {
          return $default_msg;
        }
        return $custom_msg;
    }

    return $default_msg;
}

推薦答案

更新

根據運輸區域名稱(有郵政編碼限制)嘗試以下代碼,該代碼將在運輸總行上顯示您的消息(但不會生成 woocommerce 通知):

Try the following code based on a shipping Zones name (with postcodes restrictions) that will display your message on the shipping total lines (but that will not generate a woocommerce notice):

add_action( 'woocommerce_cart_totals_after_shipping' , 'shipping_zone_targeted_postcodes_custom_notice' );
add_action( 'woocommerce_review_order_after_shipping' , 'shipping_zone_targeted_postcodes_custom_notice' );
function shipping_zone_targeted_postcodes_custom_notice() {
    // HERE DEFINE YOUR SHIPPING ZONE NAME(S)
    $targeted_zones_names = array('France'); // <======  <======  <======  <======  <======  

    // Get the customer shipping zone name
    $chosen_methods    = WC()->session->get( 'chosen_shipping_methods' ); // The chosen shipping mehod
    $chosen_method     = explode(':', reset($chosen_methods) );
    $shipping_zone     = WC_Shipping_Zones::get_zone_by( 'instance_id', $chosen_method[1] );
    $current_zone_name = $shipping_zone->get_zone_name();

    if( in_array( $current_zone_name, $targeted_zones_names ) ){
        echo '<tr class="shipping">
            <td colspan="2" style="text-align:center">' . sprintf(
                __( "You'll be charged %s more for %s zip code", "woocommerce"),
                '<strong>10%</strong>',
                '<strong>' . WC()->customer->get_shipping_postcode() . '</strong>'
            ) . '</td>
        </tr>';
    }
}

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

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

這篇關于在 Woocommerce 中顯示基于客戶送貨區域的自定義消息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 91欧美激情一区二区三区成人 | 国产一级免费视频 | 毛片一区 | 成人黄色小视频 | 精品自拍视频 | 69福利视频 | 一区二区三区在线播放 | 热久久中文字幕 | 97视频免费| a视频在线免费观看 | 午夜看片| 激情久久网 | 日本一区二区三区在线视频 | 亚洲欧美另类在线观看 | 国产精品一区二区三区免费 | 精品国产一区二区三 | 欧美精品乱码99久久蜜桃 | 99这里只有精品视频 | 欧美伊人久久 | 国产女人高潮视频 | 午夜影院福利 | 欧美精品乱码视频一二专区 | 久婷婷 | 91精品国产日韩91久久久久久 | 国产永久视频 | 手机av在线免费观看 | 免费看成人片 | 在线观看亚洲 | 精品国产aⅴ麻豆 | 日韩精品国产精品 | 国产视频一区二 | 日本视频一区二区三区 | 午夜美女福利 | 成人免费黄色片 | 成人毛片一区二区三区 | 久久中文字幕视频 | 中文字幕在线观看一区二区 | 国产在线h | 亚洲男人的天堂在线观看 | 免费毛片视频 | 欧美精品一区在线观看 |