diff --git a/includes/Api/ShippingController.php b/includes/Api/ShippingController.php index 0189e81..97b0528 100644 --- a/includes/Api/ShippingController.php +++ b/includes/Api/ShippingController.php @@ -93,17 +93,21 @@ class ShippingController extends WP_REST_Controller { } } - // Get shipping methods for this zone - $shipping_methods = $zone->get_shipping_methods( true ); // true = enabled only + // Get shipping methods for this zone (false = get all, not just enabled) + $shipping_methods = $zone->get_shipping_methods( false ); $rates = array(); foreach ( $shipping_methods as $method ) { + // Get fresh settings from database + $method->init_instance_settings(); + $is_enabled = isset( $method->instance_settings['enabled'] ) && $method->instance_settings['enabled'] === 'yes'; + $rate = array( 'id' => $method->id . ':' . $method->instance_id, 'instance_id' => $method->instance_id, 'method_id' => $method->id, 'name' => $method->get_title(), - 'enabled' => $method->enabled === 'yes', + 'enabled' => $is_enabled, ); // Get cost if available @@ -134,16 +138,20 @@ class ShippingController extends WP_REST_Controller { // Add "Rest of the World" zone (zone 0) $zone_0 = new \WC_Shipping_Zone( 0 ); - $shipping_methods = $zone_0->get_shipping_methods( true ); + $shipping_methods = $zone_0->get_shipping_methods( false ); $rates = array(); foreach ( $shipping_methods as $method ) { + // Get fresh settings from database + $method->init_instance_settings(); + $is_enabled = isset( $method->instance_settings['enabled'] ) && $method->instance_settings['enabled'] === 'yes'; + $rate = array( 'id' => $method->id . ':' . $method->instance_id, 'instance_id' => $method->instance_id, 'method_id' => $method->id, 'name' => $method->get_title(), - 'enabled' => $method->enabled === 'yes', + 'enabled' => $is_enabled, ); if ( isset( $method->cost ) && $method->cost !== '' ) {