2

In Woocommerce, I'm trying to add an estimated delivery day range on cart and checkout pages.
I have set 2 shipping Zones: Germany and other European countries (outside Germany) called "DHL Europe". I need to display a different delivery day range for Germany shipping country than other European shipping countries:

  • Germany shipping country will display "Lieferzeit 3-5 Werktage" (and when there is no shipping costs).
  • Other European shipping countries will display "Lieferzeit 5-7 Werktage"

My code attempt:

function sv_shipping_method_estimate_label( $label, $method ) {
    $label .= '<br /><small class="subtotal-tax">';
    switch ( $method->method_id ) {
        case 'flat_rate':
            $label .= 'Lieferzeit 3-5 Werktage';
            break;
        case 'free_shipping':
            $label .= 'Lieferzeit 3-5 Werktage';
            break;
        case 'international_delivery':
            $label .= 'Lieferzeit 5-7 Werktage';
    }

    $label .= '</small>';
    return $label;
}
add_filter( 'woocommerce_cart_shipping_method_full_label', 'sv_shipping_method_estimate_label', 10, 2 );

It works with the free_shipping and flat_rate shipping methods, but not for European deliveries (outside Germany).

What am I doing wrong?
How to display the correct date range for European countries (outside Germany)?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
limilo
  • 327
  • 3
  • 17
  • Do a `var_dump($method->method_id);` before your `switch` and see if it really contains what you think it does/should. – Dave Mar 21 '19 at 18:37

1 Answers1

1

You don't really need to target your shipping methods, but instead customer shipping country:

add_filter( 'woocommerce_cart_shipping_method_full_label', 'cart_shipping_method_full_label_filter', 10, 2 );
function cart_shipping_method_full_label_filter( $label, $method ) {
    // The targeted country code
    $targeted_country_code = 'DE';

    if( WC()->customer->get_shipping_country() !== $targeted_country_code ){
        $days_range = '5-7'; // International
    } else {
        $days_range = '3-5'; // Germany
    }
    return $label . '<br /><small class="subtotal-tax">' . sprintf( __("Lieferzeit %s Werktage"), $days_range ) . '</small>';
}

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

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • Thx for the help but with your code it's hiding the shipping label and the costs Before: https://s16.directupload.net/images/190321/e5x2hs4i.png after https://s17.directupload.net/images/190321/dn6twqpi.png – limilo Mar 21 '19 at 21:52
  • 1
    made my day. Allways a pleasure – limilo Mar 21 '19 at 21:59