Last active
April 1, 2026 09:50
-
-
Save xlplugins/9dd19739a3c5fd7b24f05434e311f522 to your computer and use it in GitHub Desktop.
FunnelKit PayPal + WooCommerce PayPal Payments sdk conflict
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
| /** | |
| * Plugin Name: FunnelKit PayPal + WooCommerce PayPal Payments — single SDK | |
| * Description: Optional fix when both plugins load PayPal JS SDK: removes the duplicate sdk/js tag and rewires FunnelKit script deps to PPCP’s loader. | |
| * | |
| * PayPal allows one https://www.paypal.com/sdk/js include per page. Two tags break window.paypal | |
| * (e.g. PPCP: "getFundingSources is not a function"). | |
| * | |
| * @package FunnelKit_PayPal_PPCP_Compat | |
| */ | |
| defined( 'ABSPATH' ) || exit; | |
| /** | |
| * Priority after WooCommerce PayPal Payments (10) and typical FunnelKit enqueue (10). | |
| */ | |
| add_action( | |
| 'wp_enqueue_scripts', | |
| static function () { | |
| if ( ! class_exists( '\WooCommerce\PayPalCommerce\PluginModule', false ) ) { | |
| return; | |
| } | |
| $ppcp_loader = null; | |
| if ( wp_script_is( 'ppcp-smart-button', 'enqueued' ) ) { | |
| $ppcp_loader = 'ppcp-smart-button'; | |
| } elseif ( wp_script_is( 'ppcp-add-payment-method', 'enqueued' ) ) { | |
| $ppcp_loader = 'ppcp-add-payment-method'; | |
| } | |
| if ( ! $ppcp_loader ) { | |
| // PPCP not loading on this screen — keep FunnelKit SDK only. | |
| return; | |
| } | |
| $funnelkit_handles = array( 'fkwcppcp-gateway', 'fkwcppcp-express-button', 'fkwcppcp-add-payment-method' ); | |
| $needs_patch = false; | |
| foreach ( $funnelkit_handles as $handle ) { | |
| if ( wp_script_is( $handle, 'enqueued' ) ) { | |
| $needs_patch = true; | |
| break; | |
| } | |
| } | |
| if ( ! $needs_patch ) { | |
| return; | |
| } | |
| wp_dequeue_script( 'funnelkit-paypal-sdk' ); | |
| wp_deregister_script( 'funnelkit-paypal-sdk' ); | |
| $wp_scripts = wp_scripts(); | |
| if ( ! $wp_scripts instanceof WP_Scripts ) { | |
| return; | |
| } | |
| foreach ( $funnelkit_handles as $handle ) { | |
| if ( ! isset( $wp_scripts->registered[ $handle ] ) ) { | |
| continue; | |
| } | |
| $obj = $wp_scripts->registered[ $handle ]; | |
| $deps = is_array( $obj->deps ) ? $obj->deps : array(); | |
| $deps = array_diff( $deps, array( 'funnelkit-paypal-sdk' ) ); | |
| $deps[] = $ppcp_loader; | |
| $deps = array_values( array_unique( $deps ) ); | |
| $obj->deps = $deps; | |
| } | |
| }, | |
| 100 | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment