From af28e4a7c4edbb07f8a8e1d44685e7a3e2af5c83 Mon Sep 17 00:00:00 2001 From: soufiane Date: Wed, 26 Feb 2025 17:40:03 +0100 Subject: [PATCH] wait #7330 @3:00 --- .../physioassist/resources/functions.php | 69 ++++++++++++++----- 1 file changed, 50 insertions(+), 19 deletions(-) diff --git a/wp-content/themes/physioassist/resources/functions.php b/wp-content/themes/physioassist/resources/functions.php index 224028dc..16561487 100644 --- a/wp-content/themes/physioassist/resources/functions.php +++ b/wp-content/themes/physioassist/resources/functions.php @@ -154,33 +154,41 @@ add_filter('wps_sfw_show_one_time_subscription_price', function($price) { }); add_action('woocommerce_after_add_to_cart_quantity', function($wps_skip_creating_subscription, $product_id = false) { + $app = filter_input(INPUT_GET, 'app', FILTER_SANITIZE_STRING); if(!$product_id) { global $product; } $product_id = $product_id ?? $product->get_id(); - $wps_price_html = "
"; - $wps_price_html .= "

Fréquence

"; - $wps_price_html .= '
'; - $wps_price_html .= '
'; - $wps_price_html .= '
'; - $wps_price_html .= '
'; - // translators: placeholder is price_discount_percentage. - $wps_price_html .= '
'; - $wps_price_html .= '
'; - - $wps_price_html .= "
"; + + if(!$app) { + $wps_price_html = ''; + }else { + $wps_price_html = "
"; + $wps_price_html .= "

Fréquence

"; + $wps_price_html .= '
'; + $wps_price_html .= '
'; + $wps_price_html .= '
'; + $wps_price_html .= '
'; + // translators: placeholder is price_discount_percentage. + $wps_price_html .= '
'; + $wps_price_html .= '
'; + + $wps_price_html .= "
"; + } echo $wps_price_html; }); +// add_action( 'woocommerce_update_cart_action_cart_updated', function($cart_updated){ + $app = filter_input(INPUT_GET, 'app', FILTER_SANITIZE_STRING); foreach ( WC()->cart->cart_contents as &$cart_item ) { - if($_POST['wps_type_selection'] === "one_time") { + if ($_POST['wps_type_selection'] === "one_time") { apply_filters('wps_skip_creating_subscription', true, $cart_item); $cart_item["wps_type_selection"] = "one_time"; - }else{ + } else { apply_filters('wps_skip_creating_subscription', false, $cart_item); $cart_item["wps_type_selection"] = "subscribe"; } @@ -188,6 +196,7 @@ add_action( 'woocommerce_update_cart_action_cart_updated', function($cart_update return true; }); +// Surcharger le template lié au paiement add_filter('wc_get_template', function($template, $template_name, $args, $template_path, $default_path) { if ($template_name === 'checkout/payment.php') { $custom_template = get_stylesheet_directory() . '/woocommerce/checkout/payment.blade.php'; @@ -198,19 +207,41 @@ add_filter('wc_get_template', function($template, $template_name, $args, $templa return $template; }, 10, 5); +// Nécessaire du label add_action('woocommerce_before_add_to_cart_quantity', function(){ - echo "

Quantité

"; + echo "

Quantité

"; }); +// Nécessaire pour la redirection juste après avoir ajouté au panier add_filter('woocommerce_add_to_cart_redirect', function() { $app = filter_input(INPUT_GET, 'app', FILTER_SANITIZE_STRING); if ($app == "true") { return wc_get_cart_url()."?app=true"; } - return wc_get_cart_url(); + return false; }); +// Nécessaire pour la redirection vers la page thankyou add_filter('woocommerce_get_return_url', function($return_url, $order) { $app = filter_input(INPUT_POST, '_app', FILTER_SANITIZE_STRING); - return add_query_arg('app', $app, $return_url); + if($app) { + return add_query_arg('app', $app, $return_url); + } + return $return_url; }, 10, 2); + +// API +function cancelSubscription( $data ) { + $subscriptionId = $data['id']; + do_action( 'wps_sfw_subscription_cancel', $subscriptionId, 'Cancel' ); + wps_sfw_update_meta_data( $subscriptionId, 'wps_subscription_cancelled_by', 'by_admin_bulk_action' ); + wps_sfw_update_meta_data( $subscriptionId, 'wps_subscription_cancelled_date', time() ); + return "Annulation ok"; +} + +add_action( 'rest_api_init', function () { + register_rest_route( 'wsp-route/v1', '/cancel/(?P\d+)', array( + 'methods' => 'GET', + 'callback' => 'cancelSubscription', + ) ); +} ); -- 2.39.5