Add different custom labels to Woocommerce shipping methods

只愿长相守 提交于 2019-12-02 06:45:45

Here is the correct way to do what you are expecting (you should only need to change the texts to get your correct labels):

add_filter('woocommerce_cart_shipping_method_full_label', 'custom_shipping_method_label', 10, 2);
function custom_shipping_method_label( $label, $method ){
    $rate_id = $method->id; // The Method rate ID (Method Id + ':' + Instance ID)

    // Continue only if it is "flat rate"
    if( $method->method_id !== 'flat_rate' ) return $label;

    switch ( $method->instance_id ) {
        case '3':
            $txt = __('Est delivery: 2-5 days'); // <= Additional text
            break;
        case '4':
            $txt =  __('Est delivery: 1 day'); // <= Additional text
            break;
        case '5':
            $txt =  __('Est delivery: 2-3 days'); // <= Additional text
            break;
         // for case '2' and others 'flat rates' (in case of)
        default:
            $txt =  __('Est delivery: 2-400 days'); // <= Additional text
    }
    return $label . '<br /><small>' . $txt . '</small>';
}

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

Tested and works

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!