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

在 WooCommerce 中為特定國家/地區設置最小允許重量

Set minimum allowed weight for a specific country in WooCommerce(在 WooCommerce 中為特定國家/地區設置最小允許重量)
本文介紹了在 WooCommerce 中為特定國家/地區設置最小允許重量的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試專門為哥倫比亞國家/地區應用 20 公斤的強制性最低重量,如果購物車總重量低于此最低重量,則避免結賬.

I am trying to specifically apply a mandatory minimum weight of 20 kilos for the country of Colombia avoiding checkout if the total cart weight is under this minimal weight.

這是我的實際代碼,它允許我確定最小權重:

Here is my actual code, that allow me to fix a minimum weight:

add_action( 'woocommerce_check_cart_items', 'cldws_set_weight_requirements' );
function cldws_set_weight_requirements() {
    // Only run in the Cart or Checkout pages
    if( is_cart() || is_checkout() ) {
        global $woocommerce;
        // Set the minimum weight before checking out
        $minimum_weight = 30;
        // Get the Cart's content total weight
        $cart_contents_weight = WC()->cart->cart_contents_weight;
        // Compare values and add an error is Cart's total weight
        if( $cart_contents_weight < $minimum_weight  ) {
            // Display our error message
            wc_add_notice( sprintf('<strong>A Minimum Weight of %s%s is required before checking out.</strong>'
                . '<br />Current cart weight: %s%s',
                $minimum_weight,
                get_option( 'woocommerce_weight_unit' ),
                $cart_contents_weight,
                get_option( 'woocommerce_weight_unit' ),
                get_permalink( wc_get_page_id( 'shop' ) )
                ),
            'error' );
        }
    }
}

我怎樣才能讓它只適用于哥倫比亞國家?

How can I make it work for only for Colombia country?

推薦答案

更新(針對阿根廷和哥倫比亞航運縣)

Update (for Argentina and Colombia shipping counties)

我已重新訪問您的代碼,使其僅適用于最小重量為 20 公斤的哥倫比亞.您需要檢查重量單位,因為它應該是Kg"(以公斤為單位).

I have revisited your code and make it work just for colombia with a minimal weight of 20 kilos. You will need to check the weight unit as it should be "Kg" (in Kilos).

代碼:

add_action( 'woocommerce_check_cart_items', 'checkout_required_min_weight_country_based' );
function checkout_required_min_weight_country_based() {
    // Only on Cart or Checkout pages
    if( ! ( is_cart() || is_checkout() ) ) return;

    // Get the shipping country
    $country = WC()->session->get('customer')['shipping_country'];
    if( empty($country) ){
        $country = WC()->session->get('customer')['billing_country'];
    }

    // For Colombia and Argentina shipping countries
    if( in_array( $country, array('CO', 'AR') ) ){

        // HERE Set the minimum weight
        $minimum_weight = 20; // 20 kg

        // Get the Cart's content total weight
        $total_weight = WC()->cart->get_cart_contents_weight();

        // If total weight is lower than minimum, we avoid checkout and display an error notice
        if( $total_weight < $minimum_weight  ) {
            // Display an dynamic error notice
            wc_add_notice( sprintf(
                '<strong>A Minimum Weight of %s is required before checking out.</strong>'
                . '<br />Current cart weight: %s',
                wc_format_weight($minimum_weight),
                wc_format_weight($total_weight)
            ), 'error' );
        }
    }
}

代碼位于活動子主題(或活動主題)的 function.php 文件中.經過測試和工作.

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

當哥倫比亞是檢測到的國家(或定義的國家)時,您將得到如下信息:

When Colombia is the detected country (or the defined country) you will get something like:

所有國家/地區的代碼相同:

The same code for all countries:

add_action( 'woocommerce_check_cart_items', 'checkout_required_min_weight' );
function checkout_required_min_weight() {
    // Only on Cart or Checkout pages
    if( ! ( is_cart() || is_checkout() ) ) return;

    // HERE Set the minimum weight
    $minimum_weight = 20; // 20 kg

    // Get the Cart's content total weight
    $total_weight = WC()->cart->get_cart_contents_weight();

    // If total weight is lower than minimum, we avoid checkout and display an error notice
    if( $total_weight < $minimum_weight  ) {
        // Display an dynamic error notice
        wc_add_notice( sprintf(
            '<strong>A Minimum Weight of %s is required before checking out.</strong>'
            . '<br />Current cart weight: %s',
            wc_format_weight($minimum_weight),
            wc_format_weight($total_weight)
        ), 'error' );
    }
}

代碼位于活動子主題(或活動主題)的 function.php 文件中.經過測試和工作.

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

這篇關于在 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 字節))
主站蜘蛛池模板: 一区二区国产精品 | 999久久久| 91精品久久久久久久久久 | 久久大陆 | 亚洲精品视频三区 | 蜜臀久久 | 久久久久久网站 | 亚洲三级在线 | 欧美午夜精品久久久久免费视 | 成人在线免费观看 | 九九精品热 | 精品视频在线一区 | 久久久影院| 91精品国产91久久久久久最新 | 尤物视频在线免费观看 | 国产免费播放视频 | 久久精品在线 | 成人三级网址 | 天天干天天操 | 亚洲精品久久 | 四虎影院新地址 | 成人在线观看免费 | 免费国产黄网站在线观看视频 | 日韩欧美在线精品 | 国产精品成人一区二区三区 | 欧美一区二区三区在线播放 | 精品久久久久久18免费网站 | 无码一区二区三区视频 | 国产精品福利在线 | 国产高清精品在线 | 激情国产| 一区二区不卡视频 | 久热久草 | 欧美一区二区小视频 | 毛片.com | 日本黄色不卡视频 | 91在线网 | 欧美一区免费 | 亚洲欧洲成人av每日更新 | 激情小视频| 国内精品在线视频 |