From d07835bc58a6c0e8228ad8a6457fdd46d53cda1f Mon Sep 17 00:00:00 2001 From: Yash Tripathi Date: Fri, 20 Sep 2024 17:06:58 +0530 Subject: [PATCH] Added defer in place of footer --- woo-razorpay.php | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/woo-razorpay.php b/woo-razorpay.php index 30295ce5..46b941cb 100644 --- a/woo-razorpay.php +++ b/woo-razorpay.php @@ -368,6 +368,8 @@ protected function initHooks() 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 ); } @@ -714,20 +716,30 @@ public function newTrackPluginInstrumentation($key, $secret) return new TrackPluginInstrumentation($api, $key); } - public function enqueue_checkout_js_script_on_checkout() { - // Check if we're on the checkout page - if (is_checkout()) { - // Enqueue your custom script + public function enqueue_checkout_js_script_on_checkout() + { + if (is_checkout()) + { wp_enqueue_script( - 'razorpay-checkout-js', // Handle name for the script - 'https://checkout.razorpay.com/v1/checkout.js', // Path to your script file - [], // Dependencies (like jQuery) - null, // Version number, set to null if not needed - true // Load script in footer + '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