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

在 Woocommerce 中隱藏特定產品的特定運輸方式

Hide specific shipping method for specific products in Woocommerce(在 Woocommerce 中隱藏特定產品的特定運輸方式)
本文介紹了在 Woocommerce 中隱藏特定產品的特定運輸方式的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我的 WooCommerce 商店中有一些產品很重(超過 20 公斤),需要通過某種運輸方式運輸.我想為所有包含重量超過 20 公斤的產品的購物車項目隱藏 'shipping_method_0_flat_rate2'.

I have a few products in my WooCommerce store that are to heavy (more than 20kg) to be shipped by a certain shipping method. I would like to hide 'shipping_method_0_flat_rate2' for all cart items which contain a product that is heavier than 20kg.

我嘗試調整下面的代碼片段,但它并不完整且有效:

I tried to adjust the snippet below, but it is not complete and working:

add_filter( 'woocommerce_package_rates', 'hide_shipping_based_on_tag' ,    10, 1 );
function check_cart_for_share() {

    // specify the product id's you want to hide
    $product_ID = array(
    '113', // Product name
    );
    global $woocommerce;
    $cart = $woocommerce->cart->cart_contents;

    $found = false;

    // loop through the array looking for the products. Switch to true if the product is found.
    foreach ($woocommerce->cart->cart_contents as $key => $values ) {
        $terms = get_the_terms( $values['product_id'], 'product_cat' );
        foreach ($terms as $term) {
            if( in_array( $term->term_id, $product_ID ) ) {

        $found = true;
        break;
    }
  }
}

return $found;

}

function hide_shipping_based_on_tag( $available_methods ) {

    // use the function above to check the cart for the products.
    if ( check_cart_for_share() ) {

    // remove the method you want
    unset( $available_methods['shipping_method_0_flat_rate2'] ); // Replace with the shipping option that you want to remove.
}

    // return the available methods without the one you unset.
    return $available_methods;

}

感謝任何幫助.

推薦答案

您的代碼使事情變得更加復雜,并且您的運輸方式 ID 不是很好的方式……試試這個:

You are making things more complicated in your code and your shipping method ID is not the good one… Try this instead:

add_filter( 'woocommerce_package_rates', 'specific_products_shipping_methods', 10, 2 );
function specific_products_shipping_methods( $rates, $package ) {

    $product_ids = array( 113 ); // HERE set the product IDs in the array
    $method_id = 'flat_rate:2'; // HERE set the shipping method ID
    $found = false;

    // Loop through cart items Checking for defined product IDs
    foreach( $package['contents'] as $cart_item ) {
        if ( in_array( $cart_item['product_id'], $product_ids ) ){
            $found = true;
            break;
        }
    }
    if ( $found )
        unset( $rates[$method_id] );

    return $rates;
}

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

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

您應該需要刷新運輸緩存:
1) 首先,此代碼已保存在您的 function.php 文件中.
2) 在配送設置中,輸入配送區域并禁用配送方式并保存".然后重新啟用該送貨方式并保存".大功告成.

You should need to refresh the shipping caches:
1) First this code is already saved on your function.php file.
2) In Shipping settings, enter in a Shipping Zone and disable a Shipping Method and "save". Then re-enable that Shipping Method and "save". You are done.

這篇關于在 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 字節))
主站蜘蛛池模板: 日日爱夜夜操 | 国产日产欧产精品精品推荐蛮挑 | 亚洲国产精品久久久久 | 国产一级精品毛片 | 夜夜干夜夜操 | 日韩免费一区 | 丁香婷婷在线视频 | 亚洲人成网站777色婷婷 | 成人三级视频 | 日日摸日日碰夜夜爽亚洲精品蜜乳 | 久久国产成人午夜av影院武则天 | 91精品国产综合久久小仙女图片 | 日韩久久久久久 | 亚洲精品在线播放 | 日韩精品久久久久 | 中文字幕日韩欧美 | 玖玖国产| 国产高清在线视频 | 亚洲一区 | 天堂久久网| 成人妇女免费播放久久久 | 国产一区二区激情视频 | 日韩在线免费电影 | 99综合 | 久久在看| 看av电影 | 91资源在线观看 | 国产欧美精品一区二区色综合朱莉 | 99热精品久久 | 日韩精品无码一区二区三区 | 视频一区二区三区中文字幕 | 美人の美乳で授乳プレイ | 免费毛片在线 | 男女视频在线看 | 久久www免费人成看片高清 | 亚洲视频在线观看免费 | 天堂va在线 | 亚洲成人日韩 | 围产精品久久久久久久 | 黄色毛片一级 | 国产色视频网站 |