Created
January 28, 2026 07:49
-
-
Save xlplugins/8cf944c0e1dd8ba882f997e17e4dee0d to your computer and use it in GitHub Desktop.
Trust Payments + FunnelKit Checkout Compatibility Snippet
This file contains hidden or 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
| <?php | |
| /** | |
| * Trust Payments + FunnelKit Checkout Compatibility Snippet | |
| * | |
| * Fixes two issues when using Trust Payments gateway with FunnelKit Checkout: | |
| * 1. "Form with id: 'st-form' does not exist" - SDK expects st-form but FunnelKit uses wfacp_checkout_form | |
| * 2. "Invalid card details" validation error - tp_valid_card_detail hidden field missing from form | |
| * | |
| * Usage: Add this code to your theme's functions.php or a custom plugin. | |
| * | |
| * @since 1.0.0 | |
| */ | |
| if ( ! defined( 'ABSPATH' ) ) { | |
| exit; | |
| } | |
| add_action( 'plugins_loaded', function() { | |
| // Only load if both plugins are active | |
| if ( ! class_exists( 'WFACP_Core' ) || ! defined( 'SECURETRADING_VERSION' ) ) { | |
| return; | |
| } | |
| /** | |
| * Override SecureTrading SDK formId to use FunnelKit's form ID | |
| */ | |
| add_action( 'wp_head', function() { | |
| if ( ! function_exists( 'is_checkout' ) || ! is_checkout() ) { | |
| return; | |
| } | |
| ?> | |
| <script> | |
| (function() { | |
| var checkInterval = setInterval(function() { | |
| if (typeof window.SecureTrading !== 'undefined') { | |
| clearInterval(checkInterval); | |
| var originalSecureTrading = window.SecureTrading; | |
| window.SecureTrading = function(config) { | |
| if (config && config.formId === 'st-form' && document.getElementById('wfacp_checkout_form')) { | |
| config.formId = 'wfacp_checkout_form'; | |
| } | |
| return originalSecureTrading.call(this, config); | |
| }; | |
| window.SecureTrading.prototype = originalSecureTrading.prototype; | |
| } | |
| }, 10); | |
| setTimeout(function() { clearInterval(checkInterval); }, 10000); | |
| })(); | |
| </script> | |
| <?php | |
| }, 1 ); | |
| /** | |
| * Add tp_valid_card_detail hidden field inside FunnelKit checkout form | |
| * Trust Payments uses woocommerce_checkout_after_order_review which FunnelKit doesn't fire | |
| */ | |
| add_action( 'wfacp_checkout_after_order_review', function() { | |
| static $added = false; | |
| if ( $added ) { | |
| return; | |
| } | |
| $added = true; | |
| ?> | |
| <input type="hidden" id="tp_valid_card_detail" name="tp_valid_card_detail" value="" /> | |
| <?php | |
| } ); | |
| }, 20 ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment