Puddinq.com sharing knowledge

Get all shipping methods in WooCommerce for debugging purposes

Get all shipping methods in WooCommerce for debugging purposes

Sometimes the debugging of the WooCommerce checkout page stresses you out and you need data:
(this might help)

add_action('wp_footer', function () {
    if (current_user_can('manage_options')) { // Only for admins
        $zones = WC_Shipping_Zones::get_zones(); // Get all shipping zones
        $zones[] = [
            'id' => 0,
            'zone_name' => 'Rest of the World',
            'shipping_methods' => WC_Shipping_Zones::get_zone(0)->get_shipping_methods(),
        ];

        echo '<pre>';
        foreach ($zones as $zone) {
            echo "Zone: " . $zone['zone_name'] . " (ID: " . $zone['id'] . ")\n";
            foreach ($zone['shipping_methods'] as $method_id => $method) {
                echo "  Instance ID: {$method_id}\n";
                echo "  Method Title: " . $method->title . "\n";
                echo "  Enabled: " . ($method->enabled === 'yes' ? 'Yes' : 'No') . "\n";
                echo "  Settings: " . json_encode($method->settings, JSON_PRETTY_PRINT) . "\n\n";
            }
            echo "\n";
        }
        echo '</pre>';
    }
});