WC_Shipping::load_shipping_methods PHP Method

load_shipping_methods() public method

Loads all shipping methods which are hooked in. If a $package is passed some methods may add themselves conditionally and zones will be used.
public load_shipping_methods ( array $package = [] ) : array
$package array
return array
    public function load_shipping_methods($package = array())
    {
        if (!empty($package)) {
            $debug_mode = 'yes' === get_option('woocommerce_shipping_debug_mode', 'no');
            $shipping_zone = WC_Shipping_Zones::get_zone_matching_package($package);
            $this->shipping_methods = $shipping_zone->get_shipping_methods(true);
            // Debug output
            if ($debug_mode && !defined('WOOCOMMERCE_CHECKOUT') && !wc_has_notice('Customer matched zone "' . $shipping_zone->get_zone_name() . '"')) {
                wc_add_notice('Customer matched zone "' . $shipping_zone->get_zone_name() . '"');
            }
        } else {
            $this->shipping_methods = array();
        }
        // For the settings in the backend, and for non-shipping zone methods, we still need to load any registered classes here.
        foreach ($this->get_shipping_method_class_names() as $method_id => $method_class) {
            $this->register_shipping_method($method_class);
        }
        // Methods can register themselves manually through this hook if necessary.
        do_action('woocommerce_load_shipping_methods', $package);
        // Return loaded methods
        return $this->get_shipping_methods();
    }

Usage Example

    function checkfermopoint_merchant_callback()
    {
        echo "<h1>Riepilogo ticket Fermo!Point</h1>";
        $shippings_wc = new WC_Shipping();
        $shippings = $shippings_wc->load_shipping_methods();
        $fermopoint = $shippings["Fermo!Point"];
        //echo json_encode($fermopoint->settings);
        $fermopoint_settings = $fermopoint->settings;
        $account_id = $fermopoint_settings["FERMOPOINT_ACCOUNT_ID"];
        $account_secret = $fermopoint_settings["FERMOPOINT_ACCOUNT_SECRET"];
        $sandbox = $fermopoint_settings["sandbox"];
        $url = $sandbox == "yes" ? "http://www.sandbox.fermopoint.it/api/v1.2/merchant" : "http://api.fermopoint.it/api/v1.2/merchant";
        $ts = gmdate('Y-m-d\\TH:i:s.u\\Z');
        $auth_token = hash_hmac("sha256", (string) $ts, (string) $account_id . $account_secret, false);
        $request_url = '{
			"client_id": "' . $account_id . '",
			"ts": "' . $ts . '",
			"auth_token": "' . $auth_token . '",
			"data":{}
		}';
        $request = json_encode(array("client_id" => $account_id, "auth_token" => $auth_token, "ts" => $ts, "data" => array()));
        $httpHeader = array("Content-Type: application/json; charset=\"utf-8\"", "Accept: text/json");
        $ch = curl_init();
        $connect_timeout = 5;
        //sec
        $base_time_limit = (int) ini_get('max_execution_time');
        if ($base_time_limit < 0) {
            $base_time_limit = 0;
        }
        $time_limit = $base_time_limit - $connect_timeout - 2;
        if ($time_limit <= 0) {
            $time_limit = 20;
            //default
        }
        curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $connect_timeout);
        curl_setopt($ch, CURLOPT_TIMEOUT, $time_limit);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
        curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $result = curl_exec($ch);
        $info = curl_getinfo($ch);
        if (!isset($info['http_code'])) {
            $info['http_code'] = '';
        }
        $curl_errno = curl_errno($ch);
        $curl_error = curl_error($ch);
        if (curl_errno($ch)) {
            $result = array('http_code' => $info['http_code'], 'status' => 'ERROR1', 'errno' => $curl_errno, 'error' => $curl_error, 'result' => NULL);
        } else {
            $ret = json_decode($result);
        }
        //var_dump($result);
        //var_dump($ret);
        ?>
        
        <h2>Crediti restati: <?php 
        echo $ret->credits;
        ?>
</h2>
		<h2>Ordini totali: <?php 
        echo $ret->orders_count;
        ?>
</h2>
        
        
        <table>
        
        	<?php 
        $orders = $ret->orders;
        if (count($orders) > 0) {
            foreach ($orders as $order) {
                ?>
						<tr>
							<?php 
                foreach ($order as $col) {
                    ?>
<td><?php 
                    echo $col;
                    ?>
</td><?php 
                }
                ?>
						</tr>
					<?php 
            }
        }
        ?>
        
        </table>
        
		<?php 
        curl_close($ch);
    }
All Usage Examples Of WC_Shipping::load_shipping_methods