From faa0c1ae03df361c3d16da14ce27049628e28ead Mon Sep 17 00:00:00 2001 From: soufiane Date: Tue, 4 Mar 2025 11:00:19 +0100 Subject: [PATCH] wait #7341 @0:40 --- .../physioassist/resources/functions.php | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/wp-content/themes/physioassist/resources/functions.php b/wp-content/themes/physioassist/resources/functions.php index 64716a2b..d9e30ff9 100644 --- a/wp-content/themes/physioassist/resources/functions.php +++ b/wp-content/themes/physioassist/resources/functions.php @@ -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\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\d+)', array( + 'methods' => 'GET', + 'callback' => 'listOrderStatus', + 'args' => array( + 'id' => array( + 'validate_callback' => 'is_numeric' + ), + ), ) ); } ); -- 2.39.5