Home / Disable / PayPal Commerce – PayPal Checkout using only the PayPal button
Duplicate Snippet

Embed Snippet on Your Site

PayPal Commerce – PayPal Checkout using only the PayPal button

Hide Venmo, Pay Later, Apple Pay, Google Pay buttons, and Pay Later messages from the PayPal Commerce field. Based on the code at wpforms/src/Integrations/PayPalCommerce/Frontend/Frontend.php

Ralden Souza PRO
<10
Code Preview
php
<?php
/**
 * Hide Venmo and Pay Later buttons from PayPal Commerce field.
 * Also hides Apple Pay, Google Pay buttons and Pay Later messages.
 *
 * @link https://wpforms.com/developers/wpforms_wp_footer_end/
 */
function wpf_hide_paypal_commerce_buttons() {
    ?>
    <script type="text/javascript">
    jQuery(function($) {
        // Hide Apple Pay, Google Pay and Pay Later messages via CSS classes (WPForms elements).
        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);
        // Hide Venmo and Pay Later SDK-rendered iframes via MutationObserver.
        var observer = new MutationObserver(function() {
            document.querySelectorAll('iframe[name*="venmo"], iframe[name*="paylater"]').forEach(function(iframe) {
                var wrapper = iframe.closest('.paypal-button') || iframe.parentElement;
                if (wrapper) {
                    wrapper.style.setProperty('display', 'none', 'important');
                }
            });
        });
        observer.observe(document.body, { childList: true, subtree: true });
    });
    </script>
    <?php
}
add_action( 'wpforms_wp_footer_end', 'wpf_hide_paypal_commerce_buttons', 30 );

Comments

Add a Comment