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

根據 Woocommerce 3 中的運輸類別過濾運輸方法

Filter Shipping method based on shipping class in Woocommerce 3(根據 Woocommerce 3 中的運輸類別過濾運輸方法)
本文介紹了根據 Woocommerce 3 中的運輸類別過濾運輸方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我一直在搜索代碼以過濾除本地提貨以外的任何送貨方式.

I have been searching for code to filter out any shipping methods other than local pick up, on checkout, when a product that has a specific shipping class selected (Only pickup, ex.) is in the cart (among other products).

我只發(fā)現過時的代碼并且在 WC3+ 上不起作用.

I only found code that was outdated and does not work on WC3+.

推薦答案

以下是在啟用特定運輸類別的產品時過濾掉除本地取件以外的任何運輸方式的方法:

Here is the way to filter out any shipping methods other than local pick up, when a product that has a specific shipping class enabled:

add_filter( 'woocommerce_package_rates', 'custom_shipping_rates', 100, 2 );
function custom_shipping_rates( $rates, $package ) {

    $shipping_class = 64; // HERE set the shipping class ID
    $found = false;

    // Loop through cart items Checking for the defined shipping method
    foreach( $package['contents'] as $cart_item ) {
        if ( $cart_item['data']->get_shipping_class_id() == $shipping_class ){
            $found = true;
            break;
        }
    }

    if ( ! $found ) return $rates; // If not found we exit

    // Loop through shipping methods
    foreach( $rates as $rate_key => $rate ) {
        // all other shipping methods other than "Local Pickup"
        if ( 'local_pickup' !== $rate->method_id && $found ){

            // Your code here
        }
    }

    return $rates;
}

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

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

然后在 StackOverFlow 使用 woocommerce_package_rates 搜索最近的答案 將允許您完成代碼.

Then in StackOverFlow searching for recent answer with woocommerce_package_rates will allow you to finish your code.

這篇關于根據 Woocommerce 3 中的運輸類別過濾運輸方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

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)
主站蜘蛛池模板: 蜜月aⅴ国产精品 | 久久国产激情视频 | 日韩国产黄色片 | 91在线精品播放 | 日日日干干干 | 欧美极品在线观看 | 久久久91 | 欧美日韩专区 | 在线看av的网址 | 亚洲成人黄色 | 久久久精 | 国产一区二区三区四区五区加勒比 | 国产综合久久久久久鬼色 | 亚洲天堂av在线 | 99久久精品免费看国产四区 | 国产综合精品 | 欧美成人一区二区三区 | 天堂三级| 日韩精品在线观看一区二区 | 91一区二区三区在线观看 | 99re| 69av片| 日本特黄a级高清免费大片 特黄色一级毛片 | 亚洲一区二区在线视频 | 久久伊人精品一区二区三区 | 欧洲精品码一区二区三区免费看 | h小视频 | 久久国产精品免费视频 | 亚洲视频一区在线观看 | 免费视频一区 | 日韩久久精品 | 久草精品视频 | 丁香久久 | 亚洲一区视频 | 国产精品福利视频 | 国产一区二区三区视频免费观看 | 九九久久久 | 日韩精品久久久久久 | 国产精品一区二区三区99 | 91视在线国内在线播放酒店 | 国产精品久久久久久久久久三级 |