• I need to get a chosen in cart shipping method’s label, I mean, how it’s displayed in cart page when choosing shipping method.

    I’ve got it’s slugname and id, but I can’t get it’s label in fact (or maybe there is some other way of getting the shipping method label).

    print WC()->session->get( 'chosen_shipping_methods' )[0]; //returns "table_rate_shipping_moscow"
    print WC()->session->get( 'shipping_method_counts' )[0]; //returns "56"

    Finally I should get a string Москва (which equals to table_rate_shipping_moscow in this particular case) .

    Thx in advance.

    • This topic was modified 9 years, 4 months ago by impulsgraw.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter impulsgraw

    (@impulsgraw)

    Please, help me with this question.

    Thread Starter impulsgraw

    (@impulsgraw)

    I have solved the problem myself, thank you for your quick response.
    If someone needs, there is the solution:

    $rate_table = array();
    
    $shipping_methods = WC()->shipping->get_shipping_methods();
    
    foreach($shipping_methods as $shipping_method){
    	$shipping_method->init();
    
    	foreach($shipping_method->rates as $key=>$val)
    		$rate_table[$key] = $val->label;
    }
    
    echo $rate_table[WC()->session->get( 'chosen_shipping_methods' )[0]]; //TA-DA!
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Get chosen shipping method label’ is closed to new replies.