简体   繁体   English

当 Woocommerce 提供免费送货时,仅禁用统一费率送货方式

[英]Disable only flat rate shipping method when free shipping is available in Woocommerce

I am using Hide specifics Flat Rates when Free Shipping is available in WooCommerce 3 lightly changed answer code to hide all shipping methods except one. 当 WooCommerce 3 中的免费送货可用时,我正在使用隐藏具体统一费率稍微更改答案代码以隐藏除一种之外的所有送货方式。 The only method I want showing is a rate from the "Woocommerce Advanced Shipping" plugin .我想要显示的唯一方法是来自“Woocommerce Advanced Shipping”插件的费率。

I am using the correct rate ID etc...我正在使用正确的费率 ID 等...

Everything works fine except when a customer tries to click that shipping method, it won't stay selected.一切正常,除非客户尝试单击该运输方式,否则它不会保持选中状态。 It just jumps back to free shipping.它只是跳回免费送货。

I have tried debugging and also tried the code with a native woocommerce flat rate ID and it showed up/able to select it just fine.我试过调试,也试过使用本地 woocommerce 统一费率 ID 的代码,它显示/能够选择它就好了。

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

    $flat_rates_express = array( '2588' );

    $free = $flat2 = array();
    foreach ( $rates as $rate_key => $rate ) {
        // Updated Here To 
        if ( in_array( $rate->id, $flat_rates_express ) )
            $flat2[ $rate_key ] = $rate;
        if ( 'free_shipping:12' === $rate->id )
            $free[ $rate_key ] = $rate;
    }
        return ! empty( $free ) ? array_merge( $free, $flat2 ) : $rates;
}

ID I want to Keep Shown: "2588" (Custom Shipping Rate From Plugin)我想保持显示的 ID:“2588”(来自插件的自定义运费)

How can I disable the Flat rate shipping method when free shipping is available o and keep a custom shipping rate (from a plugin)?当免费送货可用 o 时,如何禁用统一运费方法并保持自定义运费(来自插件)?

As you have 3 shipping methods, 1 free shipping, 1 flat rate and 1 custom '2588', it's possible to hide the flat rate shipping method when free shipping is available instead:由于您有 3 种送货方式,1 种免费送货、1 种统一费率和 1 种自定义“2588”,因此可以在提供免费送货服务时隐藏统一费率送货方式:

add_filter( 'woocommerce_package_rates', 'free_shipping_disable_flat_rate', 1000, 2 );
function free_shipping_disable_flat_rate( $rates, $package ) {
    // Here your free shipping rate Id
    $free_shipping_rate_id = 'free_shipping:12';

    // When your Free shipping method is available
    if ( array_key_exists( $free_shipping_rate_id, $rates ) ) {
        // Loop through shipping methods rates
        foreach ( $rates as $rate_key => $rate ) {
            // Removing "Flat rate" shipping method
            if ( 'flat_rate' === $rate->method_id ){
                unset($rates[$rate_key]);
            }
        }
    }
    return $rates;
}

Code goes in functions.php file of your active child theme (or active theme).代码位于活动子主题(或活动主题)的 functions.php 文件中。 Tested and works.测试和工作。

Refresh the shipping caches:刷新运输缓存:

  1. This code is already saved on your function.php file.此代码已保存在您的 function.php 文件中。
  2. In a shipping zone settings, disable / save any shipping method, then enable back / save.在运输区域设置中,禁用/保存任何运输方式,然后启用返回/保存。
    You are done and you can test it.你已经完成了,你可以测试它。

hello i want to hide the flat rate shipping method when free shipping is available and the order amount is above 50.00 euros but to keep the store pickup and deliver with our driver shipping methods你好,我想在免费送货且订单金额超过 50.00 欧元时隐藏统一费率送货方式,但要保持商店提货并使用我们的司机送货方式送货

https://prnt.sc/25zr0o5 https://prnt.sc/25zr0o5

i added this code in my website philsgranola.gr in the dashboard > appearance>theme editor > functions php of the theme as this theme does not have a child theme and still the flat rate is not hidden when free shipping is available我在我的网站 philsgranola.gr 的仪表板>外观>主题编辑器>功能php中添加了此代码,因为该主题没有子主题,并且在免费送货时仍然没有隐藏统一费率

https://prnt.sc/25zrhxn https://prnt.sc/25zrhxn

can u please help?你能帮忙吗?

https://prnt.sc/25zr4yq https://prnt.sc/25zr4yq

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当 WooCommerce 中提供免费送货时,仅禁用特定的统一费率送货方式 - Disable only specific flat rate shipping method when free shipping is available in WooCommerce 当 Woocommerce 提供免费送货服务时,隐藏运费统一费率” - Hide shipping Flat rate" when free shipping is available in Woocommerce 当 WooCommerce 提供免费送货时隐藏特定的送货方式 - Hide specific shipping method when Free Shipping is available in WooCommerce 在 Woocommerce 中为所选产品禁用特定的统一费率运输方式 - Disable a specific of flat rate shipping method for a selected product in Woocommerce 当 WooCommerce 3 中提供免费送货时,隐藏细节统一费率 - Hide specifics Flat Rates when Free Shipping is available in WooCommerce 3 在woocommerce中将“统一费率”运输方式设置为默认值 - Set “flat rate” shipping method as default in woocommerce 在 WooCommerce 中为“统一费率”运输方式添加工具提示 - Add tooltip to “flat rate” shipping method in WooCommerce WooCommerce - 当免费送货可用时隐藏其他送货方式 - WooCommerce - Hide other shipping methods when FREE SHIPPING is available 基于 Woocommerce 中项目数量的渐进式统一运费方法 - Progressive Flat rate shipping method based on item quantity in Woocommerce 如果在 Woocommerce 中应用了特定的优惠券,则更改统一费率运输方式成本 - Change Flat rate shipping method cost if a specific coupon is applied in Woocommerce
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM