Last active
March 19, 2020 19:14
-
-
Save vanbo/b6ef48b26b03276aa6b212e9a7a690d5 to your computer and use it in GitHub Desktop.
wc-paysafe-checkoutjs-automatically-open-form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'wp_footer', 'prefix_add_script_to_footer' ); | |
/** | |
* Adds a script to automatically load the Paysafe Layover on the WooCommerce pay page | |
*/ | |
function prefix_add_script_to_footer() { | |
if ( ! is_checkout_pay_page() ) { | |
return; | |
} | |
?> | |
<script> | |
/** | |
* This is JavaScript code and it should be added to any file that will load it on the WooCommerce "Pay" Page | |
* | |
* The code will automatically start the Payment form without requiring the customer to click on the Pay button. | |
* Important: Keep in mind that if you allow Tokenization, the customer will not be allowed to choose to save their card or not | |
*/ | |
(function ($) { | |
$(document).ready(function () { | |
var isPayPage = $('body').hasClass('woocommerce-order-pay'); | |
if (true === isPayPage) { | |
setTimeout(function () { | |
$('#paysafe_checkout_payment_form').submit(); | |
}, 800); | |
} | |
}); | |
})(jQuery); | |
</script> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment