Created backend API for fetching WooCommerce shipping zones. New Files: - includes/Api/ShippingController.php Features: ✅ GET /settings/shipping/zones endpoint ✅ Fetches all WooCommerce shipping zones ✅ Includes shipping methods for each zone ✅ Handles "Rest of the World" zone (zone 0) ✅ Returns formatted region names ✅ Returns method costs (Free, Calculated, or price) ✅ Permission check: manage_woocommerce Data Structure: - id: Zone ID - name: Zone name - order: Display order - regions: Comma-separated region names - rates: Array of shipping methods - id: Method instance ID - name: Method title - price: Formatted price or "Free"/"Calculated" - enabled: Boolean Integration: - Registered in Routes.php - Uses WC_Shipping_Zones API - Compatible with all WooCommerce shipping methods
60 lines
2.1 KiB
PHP
60 lines
2.1 KiB
PHP
<?php
|
|
namespace WooNooW\Api;
|
|
|
|
use WP_REST_Request;
|
|
use WP_REST_Response;
|
|
use WooNooW\Api\CheckoutController;
|
|
use WooNooW\Api\OrdersController;
|
|
use WooNooW\Api\AnalyticsController;
|
|
use WooNooW\Api\AuthController;
|
|
use WooNooW\API\PaymentsController;
|
|
use WooNooW\API\StoreController;
|
|
use WooNooW\Api\ShippingController;
|
|
|
|
class Routes {
|
|
public static function init() {
|
|
// Initialize controllers (register action hooks)
|
|
OrdersController::init();
|
|
|
|
add_action('rest_api_init', function () {
|
|
$namespace = 'woonoow/v1';
|
|
|
|
// Auth endpoints (public - no permission check)
|
|
register_rest_route( $namespace, '/auth/login', [
|
|
'methods' => 'POST',
|
|
'callback' => [ AuthController::class, 'login' ],
|
|
'permission_callback' => '__return_true',
|
|
] );
|
|
|
|
register_rest_route( $namespace, '/auth/logout', [
|
|
'methods' => 'POST',
|
|
'callback' => [ AuthController::class, 'logout' ],
|
|
'permission_callback' => '__return_true',
|
|
] );
|
|
|
|
register_rest_route( $namespace, '/auth/check', [
|
|
'methods' => 'GET',
|
|
'callback' => [ AuthController::class, 'check' ],
|
|
'permission_callback' => '__return_true',
|
|
] );
|
|
|
|
// Defer to controllers to register their endpoints
|
|
CheckoutController::register();
|
|
OrdersController::register();
|
|
AnalyticsController::register_routes();
|
|
|
|
// Payments controller
|
|
$payments_controller = new PaymentsController();
|
|
$payments_controller->register_routes();
|
|
|
|
// Store controller
|
|
$store_controller = new StoreController();
|
|
$store_controller->register_routes();
|
|
|
|
// Shipping controller
|
|
$shipping_controller = new ShippingController();
|
|
$shipping_controller->register_routes();
|
|
});
|
|
}
|
|
}
|