php - Select woocommerce chosen shipping method price -
i'm trying select chosen_shipping_method price in woocommerce using code:
$packages = wc()->shipping->get_packages(); foreach ($packages $i => $package) { $chosen_method = isset(wc()->session->chosen_shipping_methods[$i]) ? wc()->session->chosen_shipping_methods[$i] : ''; } echo $chosen_method;
the code works, prints id, , cannot figure out how make print out price.
here's package structure:
what code table_rate_shipping_shipping_self_install
, need cost selected element, , not id.
i tried change code this:
foreach ($packages $i => $package['rates']) { $chosen_method = isset(wc()->session->chosen_shipping_methods[$i]) ? wc()->session->chosen_shipping_methods[$i] : ''; }
but printed out id, same before.
any ideas? sorry i'm bit new php. in advance
did try inside foreach loop?
$rate = $package['rates'][$chosen_method]->cost;
Comments
Post a Comment