]> _ Git - physioassist-wordpress.git/commitdiff
wait #7341 @0:40
authorsoufiane <soufiane@cubedesigners.com>
Tue, 4 Mar 2025 10:00:19 +0000 (11:00 +0100)
committersoufiane <soufiane@cubedesigners.com>
Tue, 4 Mar 2025 10:00:19 +0000 (11:00 +0100)
wp-content/themes/physioassist/resources/functions.php

index 64716a2b1957ae57aefb95df8af9fc906a15d7ee..d9e30ff906a274b6d4b6899b2574f8d8523f868a 100644 (file)
@@ -262,10 +262,38 @@ function wps_wsp_subscription_permission_check($request){
     return $instance->wps_wsp_subscription_permission_check($request);
 }
 
+function listOrderStatus($request) {
+    $args = array(
+        'limit' => -1,
+        'customer_id' => $request['id']
+    );
+    $orders = wc_get_orders( $args );
+
+    if ( empty( $orders ) ) {
+        return new WP_Error( 'no_order', 'Aucune commande trouvĂ©e pour cet utilisateur', array( 'status' => 404 ) );
+    }
+
+    $array = ['code' => 200,'status' => 'success'];
+    $array['data'] = array_map(function($n) {
+        return [
+            'order_id' => $n->get_id(),
+            'customer_id' => $n->get_customer_id(),
+            'total' => $n->get_total().$n->get_currency(),
+            'status' => $n->get_status(),
+        ];
+    }, $orders);
+    return new WP_REST_Response($array, 200);
+}
+
 add_action( 'rest_api_init', function () {
     register_rest_route( 'wsp-route/v1', '/cancel/(?P<id>\d+)', array(
         'methods' => 'GET',
         'callback' => 'cancelSubscription',
+        'args' => array(
+            'id' => array(
+                'validate_callback' => 'is_numeric'
+            ),
+        ),
     ) );
 } );
 
@@ -274,6 +302,23 @@ add_action( 'rest_api_init', function () {
         'methods' => 'GET',
         'callback' => 'listSubscriptionByUserId',
         'permission_callback' => 'wps_wsp_subscription_permission_check',
+        'args' => array(
+            'id' => array(
+                'validate_callback' => 'is_numeric'
+            ),
+        ),
+    ) );
+} );
+
+add_action( 'rest_api_init', function () {
+    register_rest_route( 'wsp-route/v1', '/orders-status/(?P<id>\d+)', array(
+        'methods' => 'GET',
+        'callback' => 'listOrderStatus',
+        'args' => array(
+            'id' => array(
+                'validate_callback' => 'is_numeric'
+            ),
+        ),
     ) );
 } );