id = 'asmplsww'; // Id for your shipping method. Should be uunique. $this->method_title = __('Advanced Shipping Manager'); // Title shown in admin $this->method_description = __('Description of your shipping method'); // Description shown in admin $this->enabled = "yes"; // This can be added as an setting but for this example its forced enabled $this->title = 'Advanced Shipping Managerg';// This can be added as an setting but for this example its forced. $this->init(); } function init() { // Load the settings API $this->init_form_fields(); // This is part of the settings API. Override the method to add your own settings $this->init_settings(); // This is part of the settings API. Loads settings you previously init. // Save settings in admin if you have any defined add_action('woocommerce_update_options_shipping_' . $this->id, array($this, 'add_asmplsww_shipping_method')); } public function calculate_shipping($package = array()) { //live query include_once 'asmplsww_query_live.php'; //Shipping API if (!class_exists('ASMPLSWW_Shipping_Api')) { include_once 'asmplsww_shipping_api.php'; } try { $shippingValues = ASMPLSWW_Shipping_Api::asmplswwGetShippingValue($xml_data); } catch (Exception $e) { $message = $e->getMessage(); $messageType = "error"; wc_add_notice($message, $messageType); } if (!empty($shippingValues)) { foreach ($shippingValues as $key => $value) { $shipping_rate = array( 'id' => 'key_' . $key, 'label' => $shippingValues[$key]['Name'], 'cost' => $shippingValues[$key]['Rate'] ); $this->add_rate($shipping_rate); } } } } } } add_action('woocommerce_shipping_init', 'asmplsww_shipping_method_init'); function asmplsww_shipping_method_add($methods) { $methods[] = 'ASMPLSWW_Shipping_Method'; return $methods; } add_filter('woocommerce_shipping_methods', 'asmplsww_shipping_method_add');