In WooCommerce includes\class-express-checkout-gateway.php
file I am getting shipping method Id by the following code:
$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
It gets flat_rate:1
, but I need its title - Flat Rate
.
I have already tried all this answers and many more.
How can I get this?
$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]];
Try like this