M
M
Muvka2018-12-19 10:55:20
WooCommerce
Muvka, 2018-12-19 10:55:20

How to display delivery methods on the main page?

I was only able to get to the instance_id, but I can't find a query on the wp_options table that gets info about shipping methods.

$WC_Shipping_Zone_Data_Store = new WC_Shipping_Zone_Data_Store();
print_r($WC_Shipping_Zone_Data_Store->get_methods(1, true));

Understood a little more. Found the WC_Shipping_Zones class. It has a get_zones() method. Who can tell if it can be used? It just has a get_shipping_method( $instance_id ) method. It will probably be much slower if I pass one instance_id to this method, which I get in the code above ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Muvka, 2018-12-19
@Muvka

Found a solution to the issue.

foreach(WC_Shipping_Zones::get_zones()[1]['shipping_methods'] as $method) {
  if($method->id === 'flat_rate') {
    echo '<li>' . $method->instance_settings['title'] . ': ' . wc_price($method->instance_settings['cost']) . '</li>';
  }
}

[1] are countries. I have one)
Addition. For 2 methods, processing time: 0.026161s
But in this form, the script works much faster:
$WC_Shipping_Zone_Data_Store = new WC_Shipping_Zone_Data_Store();
foreach($WC_Shipping_Zone_Data_Store->get_methods(1, true) as $method) {
  if($method->method_id === 'flat_rate') {
    $m = WC_Shipping_Zones::get_shipping_method($method->instance_id);
    echo '<li>' . $m->instance_settings['title'] . ': ' . wc_price($m->instance_settings['cost']) . '</li>';
  }
}

Script running time:0.004519

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question