1

I've been trying to create a simple shortcode function so I could display in the frontend of my website a list of available Shipping Zones along with their most reliable information such as the zone name, the country or state, the method title, the cost, as also all the zip codes attached to each shipping zone.

I’m able to retrieve all the shipping zones names by making a simple loop with the help of WooCommerce get_zones() function, but it returns an incredible confusing array of stdClass objects, so the other stuff I need to list are too deep within the array and that goes beyond my development skills.

Could anyone guide me on how to achieve that?

The function:

function shipping_zones_shortcode() {

    $delivery_zones = WC_Shipping_Zones::get_zones();

    foreach ( (array) $delivery_zones as $key => $the_zone ) {
      echo ''.$the_zone['zone_name'].', ';

      print_r($delivery_zones);

    }
}

add_shortcode( 'list_shipping_zones', 'shipping_zones_shortcode', 10 );

I'm printing the $delivery_zones array just to get a clue of what it returns, an absolutely crazy multidimensional array, a trimmed e.g bellow:


Array ( [1] => Array ( [zone_id] => 1 [zone_name] => Betim - Centro [zone_order] => 0 [zone_locations] => Array ( [0] => stdClass Object ( [code] => BR [type] => country ) [1] => stdClass Object ( [code] => BR:MG [type] => state ) [2] => stdClass Object ( [code] => 32600-010 [type] => postcode ) [3] => stdClass Object ( [code] => 32600-042 [type] => postcode ) [4] => stdClass Object ( [code] => 32600-210 [type] => postcode ) [5] => stdClass Object ( [code] => 32600-066 [type] => postcode ) [6] => stdClass Object ( [code] => 32600-032 [type] => postcode ) [7] => stdClass Object ( [code] => 32600-215 [type] => postcode ) [8] => stdClass Object ( [code] => 32600-065 [type] => postcode ) [9] => stdClass Object ( [code] => 32600-056 [type] => postcode ) [10] => stdClass Object ( [code] => 32600-055 [type] => postcode ) ) [meta_data] => Array ( ) [formatted_zone_location] => Brasil, Minas Gerais, 32600-010, 32600-042, 32600-210, 32600-066, 32600-032, 32600-215, 32600-065, 32600-056 e 104 outras regiões [shipping_methods] => Array ( [1] => WC_Shipping_Flat_Rate Object ( [fee_cost:protected] => [supports] => Array ( [0] => shipping-zones [1] => instance-settings [2] => instance-settings-modal ) [id] => flat_rate [method_title] => Taxa fixa [method_description] => Permite cobrar uma taxa fixa de entrega. [enabled] => yes [title] => Entrega em domicílio [rates] => Array ( ) [tax_status] => none [fee] => [minimum_fee] => [instance_id] => 1 [instance_form_fields] => Array ( [title] => Array ( [title] => Título do método [type] => text [description] => Isto controla o título que o usuário vê durante a finalização da compra. [default] => Taxa fixa [desc_tip] => 1 ) [tax_status] => Array ( [title] => Situação fiscal [type] => select [class] => wc-enhanced-select [default] => taxable [options] => Array ( [taxable] => Tributável [none] => Nenhum ) ) [cost] => Array ( [title] => Custo [type] => text [placeholder] => [description]...

closed as off-topic by fuxia Dec 21 '16 at 17:46

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.