English 中文(简体)
2个船运区可享受免费船运率
原标题:Unset Specific Shipping Rate When Free Shipping Rate is Available for 2 Shipping zones

我发现这一法典:

/**
 * @snippet       Hide one shipping rate when Free Shipping is available
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 6
 * @community     https://businessbloomer.com/club/
 */
  
add_filter(  woocommerce_package_rates ,  bbloomer_unset_shipping_when_free_is_available_in_zone , 9999, 2 );
   
function bbloomer_unset_shipping_when_free_is_available_in_zone( $rates, $package ) {
   // Only unset rates if free_shipping is available
   if ( isset( $rates[ free_shipping:8 ] ) ) {
      unset( $rates[ flat_rate:1 ] );
   }     
   return $rates;
}

我只能用这来增加一条自由船运和一条统一费率,因为我有2个船运区,因此,我想使用这部法典,用于2个自由船运和2个统一费率。 如何做到这一点?

我使用了该守则,并努力建造一个航运区,但我需要为此而努力。

问题回答

您可以调整这一功能,通过各航运区进行航道,并检查该区是否有自由航运:

add_filter(  woocommerce_package_rates ,  bbloomer_unset_shipping_when_free_is_available_in_zones , 9999, 2 );

function bbloomer_unset_shipping_when_free_is_available_in_zones( $rates, $package ) {
    // Get all shipping zones
    $zones = WC_Shipping_Zones::get_zones();

    foreach ( $zones as $zone ) {
        // Get the zone ID
        $zone_id = $zone[ zone_id ];

        // Check if free shipping is available in the current zone
        if ( isset( $rates["free_shipping:$zone_id"] ) ) {
            // Unset flat rates for the current zone
            unset( $rates["flat_rate:$zone_id"] );
        }
    }

    return $rates;
}

该守则将穿过所有航运区,并在有自由航运的每个区公布统一费率。

为使您的法典适用于多个航运区,首先,你们需要获得所有涉及的航运费率。 每一航运区的身份证编号如下:

add_filter(  woocommerce_package_rates ,  filter_woocommerce_package_rates , 9999, 2 );
function filter_woocommerce_package_rates( $rates, $package ) {
    // Here below define the related shipping methods rate IDs for each shipping zone
    $shipping_data = array(
        array( free  =>  free_shipping:8 ,   flat  =>  flat_rate:1 ), // first zone
        array( free  =>  free_shipping:10 ,  flat  =>  flat_rate:5 ), // other zone
    );

    // Loop through shipping data array
    foreach ( $shipping_data as $data_zone ) {
        if ( isset($rates[$data_zone[ free ]],$rates[$data_zone[ flat ]]) ) {
            unset($rates[$data_zone[ flat ]]);
        }
    }
    return $rates;
}

《刑法》生效。 网址是你的孩子主题(或gin)。 它应当发挥作用。

<>Important: 你们将不得不空出车,以更新运输方法。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签