Home / Disable / Force PayPal Commerce to render only the PayPal button
Duplicate Snippet

Embed Snippet on Your Site

Force PayPal Commerce to render only the PayPal button

With PayPal Commerce 2.0.0 and later, remove Venmo and Credit buttons from the checkout flow. Also hides Apple Pay, Google Pay buttons, and Pay Later messages.

Ralden Souza PRO
<10
Code Preview
php
<?php
/**
 * Force PayPal Commerce to render only the PayPal button.
 * Removes Venmo and Credit buttons from the checkout flow.
 * Also hides Apple Pay, Google Pay buttons and Pay Later messages.
 *
 * @link https://wpforms.com/developers/wpforms_wp_footer_end/
 */
function wpf_paypal_commerce_single_button() {
    ?>
    <script type="text/javascript">
    (function() {
        function waitForJQuery(callback) {
            if (typeof jQuery !== 'undefined') {
                callback(jQuery);
            } else {
                setTimeout(function() { waitForJQuery(callback); }, 50);
            }
        }
        waitForJQuery(function($) {
            // Force only PayPal button — excludes Venmo and Credit.
            $(document).on('loadPPScript', function(e, formID, buttonArgs) {
                if (typeof wpforms_paypal_single !== 'undefined' && wpforms_paypal_single.FUNDING) {
                    buttonArgs.fundingSource = wpforms_paypal_single.FUNDING.PAYPAL;
                }
            });
            // Hide Apple Pay, Google Pay and Pay Later messages via CSS classes.
            var style = document.createElement('style');
            style.innerHTML = [
                '.wpforms-paypal-commerce-applepay-button { display: none !important; }',
                '.wpforms-paypal-commerce-googlepay-button { display: none !important; }',
                '.wpforms-paypal-commerce-messages { display: none !important; }'
            ].join('');
            document.head.appendChild(style);
        });
    })();
    </script>
    <?php
}
add_action( 'wpforms_wp_footer_end', 'wpf_paypal_commerce_single_button', 5 );

Comments

Add a Comment