Skip to content

Instantly share code, notes, and snippets.

@vanbo
Last active March 19, 2020 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanbo/b6ef48b26b03276aa6b212e9a7a690d5 to your computer and use it in GitHub Desktop.
Save vanbo/b6ef48b26b03276aa6b212e9a7a690d5 to your computer and use it in GitHub Desktop.
wc-paysafe-checkoutjs-automatically-open-form
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