Listing and displaying WooCommerce Shipping Zones in the frontend? [closed]

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 ( => BR [type] => country ) [1] => stdClass Object ( => BR:MG [type] => state ) [2] => stdClass Object ( => 32600-010 [type] => postcode ) [3] => stdClass Object ( => 32600-042 [type] => postcode ) [4] => stdClass Object ( => 32600-210 [type] => postcode ) [5] => stdClass Object ( => 32600-066 [type] => postcode ) [6] => stdClass Object ( => 32600-032 [type] => postcode ) [7] => stdClass Object ( => 32600-215 [type] => postcode ) [8] => stdClass Object ( => 32600-065 [type] => postcode ) [9] => stdClass Object ( => 32600-056 [type] => postcode ) [10] => stdClass Object ( => 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 Listing and displaying WooCommerce Shipping Zones in the frontend? [closed] => Entrega em domicílio [rates] => Array ( ) [tax_status] => none [fee] => [minimum_fee] => [instance_id] => 1 [instance_form_fields] => Array ( Listing and displaying WooCommerce Shipping Zones in the frontend? [closed] => Array ( Listing and displaying WooCommerce Shipping Zones in the frontend? [closed] => Título do método [type] => text Listing and displaying WooCommerce Shipping Zones in the frontend? [closed] => 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 ( Listing and displaying WooCommerce Shipping Zones in the frontend? [closed] => Situação fiscal [type] => select [class] => wc-enhanced-select [default] => taxable [options] => Array ( [taxable] => Tributável [none] => Nenhum ) ) [cost] => Array ( Listing and displaying WooCommerce Shipping Zones in the frontend? [closed] => Custo [type] => text [placeholder] => Listing and displaying WooCommerce Shipping Zones in the frontend? [closed]...

0

Leave a Comment