public function get_shipping_methods($enabled_only = false)
{
if (null === $this->get_id()) {
return array();
}
$raw_methods = $this->data_store->get_methods($this->get_id(), $enabled_only);
$wc_shipping = WC_Shipping::instance();
$allowed_classes = $wc_shipping->get_shipping_method_class_names();
$methods = array();
foreach ($raw_methods as $raw_method) {
if (in_array($raw_method->method_id, array_keys($allowed_classes), true)) {
$class_name = $allowed_classes[$raw_method->method_id];
// The returned array may contain instances of shipping methods, as well
// as classes. If the "class" is an instance, just use it. If not,
// create an instance.
if (is_object($class_name)) {
$class_name_of_instance = get_class($class_name);
$methods[$raw_method->instance_id] = new $class_name_of_instance($raw_method->instance_id);
} else {
// If the class is not an object, it should be a string. It's better
// to double check, to be sure (a class must be a string, anything)
// else would be useless
if (is_string($class_name) && class_exists($class_name)) {
$methods[$raw_method->instance_id] = new $class_name($raw_method->instance_id);
}
}
// Let's make sure that we have an instance before setting its attributes
if (is_object($methods[$raw_method->instance_id])) {
$methods[$raw_method->instance_id]->method_order = absint($raw_method->method_order);
$methods[$raw_method->instance_id]->enabled = $raw_method->is_enabled ? 'yes' : 'no';
$methods[$raw_method->instance_id]->has_settings = $methods[$raw_method->instance_id]->has_settings();
$methods[$raw_method->instance_id]->settings_html = $methods[$raw_method->instance_id]->supports('instance-settings-modal') ? $methods[$raw_method->instance_id]->get_admin_options_html() : false;
}
}
}
uasort($methods, 'wc_shipping_zone_method_order_uasort_comparison');
return apply_filters('woocommerce_shipping_zone_shipping_methods', $methods, $raw_methods, $allowed_classes, $this);
}