From a83468ded0f8be353e5e5d837ac9f3cd320aad6b Mon Sep 17 00:00:00 2001 From: yashgit891 <56789472+yashgit891@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:21:53 +0530 Subject: [PATCH] [PO-212]:-Enqueue checkout.js to checkout page (#573) * Enqueue checkout.js to checkout page --- woo-razorpay.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/woo-razorpay.php b/woo-razorpay.php index f8c69d10..46b941cb 100644 --- a/woo-razorpay.php +++ b/woo-razorpay.php @@ -366,6 +366,10 @@ protected function initHooks() add_action( "woocommerce_update_options_payment_gateways_{$this->id}", 'syncPluginFetchCron'); } + add_action('wp_enqueue_scripts', array($this, 'enqueue_checkout_js_script_on_checkout')); + + add_filter('script_loader_tag', array($this, 'add_defer_to_checkout_js'), 10, 3); + add_filter( 'woocommerce_thankyou_order_received_text', array($this, 'getCustomOrdercreationMessage'), 20, 2 ); } @@ -712,6 +716,30 @@ public function newTrackPluginInstrumentation($key, $secret) return new TrackPluginInstrumentation($api, $key); } + public function enqueue_checkout_js_script_on_checkout() + { + if (is_checkout()) + { + wp_enqueue_script( + 'razorpay-checkout-js', + 'https://checkout.razorpay.com/v1/checkout.js', + [], + null, + false // Load script in footer + ); + } + } + + public function add_defer_to_checkout_js($tag, $handle, $src) + { + if ('razorpay-checkout-js' === $handle) + { + return '' . "\n"; + } + + return $tag; + } + public function pluginInstrumentation() { if (empty($_POST['woocommerce_razorpay_key_id']) or