如果有其他可用的方法,则隐藏“ Rest of the World” Woocommerce 3

时间:2018-11-19 12:59:15

标签: methods woocommerce shipping

在尝试使用“ dpdfrance_relais”方法时,我尝试隐藏值为“ colissimo_shippingzone_method_home1:3:1”的“世界其他地区”运输方法。

以下是可用运输方式的源代码:

<ul id="shipping_method">
<li>
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_colissimo_shippingzone_method_home131" value="colissimo_shippingzone_method_home1:3:1" class="shipping_method"  checked='checked' />
<label for="shipping_method_0_colissimo_shippingzone_method_home131">Livraison Monde 0-500g: <span class="woocommerce-Price-amount amount">32,04<span class="woocommerce-Price-currencySymbol">&euro;</span></span></label>                 </li>
<li>
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_dpdfrance_relais" value="dpdfrance_relais" class="shipping_method"  />
<label for="shipping_method_0_dpdfrance_relais">Retrait en point relais: <span class="woocommerce-Price-amount amount">7,48<span class="woocommerce-Price-currencySymbol">&euro;</span></span></label></li>
<li>
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_dpdfrance_predict" value="dpdfrance_predict" class="shipping_method"  />
<label for="shipping_method_0_dpdfrance_predict">Expédition à domicile: <span class="woocommerce-Price-amount amount">10,26<span class="woocommerce-Price-currencySymbol">&euro;</span></span></label></li>
</ul>

我尝试使用此函数(I Found here)修改我的方法的名称,但无法正常工作:

    /**
     * Hide shipping rates when dpd shipping is available, but keep "other" 
     * Updated to support WooCommerce 2.6 Shipping Zones
     */

    function hide_shipping_when_dpd_is_available( $rates, $package ) {
        $new_rates = array();
        foreach ( $rates as $rate_id => $rate ) {
            // Only modify rates if dpdfrance_relais is present.
            if ( 'dpdfrance_relais' === $rate->method_id ) {
                $new_rates[ $rate_id ] = $rate;
                break;
            }
        }

        if ( ! empty( $new_rates ) ) {
            //Save local pickup if present.
            foreach ( $rates as $rate_id => $rate ) {
                if ('local_pickup' === $rate->method_id ) {
                    $new_rates[ $rate_id ] = $rate;
                    break;
                }
            }
           //Save dpdfrance_predict if present.
            foreach ( $rates as $rate_id => $rate ) {
                if ('dpdfrance_predict' === $rate->method_id ) {
                    $new_rates[ $rate_id ] = $rate;
                    break;
                }
            }
            return $new_rates;
        }

        return $rates;
    }

    add_filter( 'woocommerce_package_rates', 'hide_shipping_when_dpd_is_available', 10, 2 );

有人可以帮助我吗?

0 个答案:

没有答案