Home / Disable / PayPal Commerce – Horizontal layout for payment buttons
Duplicate Snippet

Embed Snippet on Your Site

PayPal Commerce – Horizontal layout for payment buttons

Switch to horizontal view and display only the PayPal, Apple Pay, and Google Pay buttons. Based on the code at wpforms/src/Integrations/PayPalCommerce/Frontend/Frontend.php

Ralden Souza PRO
<10
Code Preview
php
<?php
/**
 * PayPal Commerce customizations for form 877:
 * - Horizontal layout for payment buttons
 * - Disable card funding source from SDK
 * - Hide "Powered by PayPal" element
 *
 * @link https://wpforms.com/developers/wpforms_wp_footer_end/
 */
// Inject CSS for horizontal button layout
function citation_paypal_horizontal_css() {
    ?>
    <style>
    #wpforms-877 .wpforms-paypal-commerce-single-submit-button {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
    }
    #wpforms-877 .wpforms-paypal-commerce-applepay-button,
    #wpforms-877 .wpforms-paypal-commerce-googlepay-button,
    #wpforms-877 .paypal-buttons,
    #wpforms-877 .wpforms-paypal-commerce-messages {
        flex: 1;
        min-width: 140px;
    }
    .wpforms-paypal-commerce-messages {
        display: none !important;
    }
    </style>
    <?php
}
add_action( 'wp_head', 'citation_paypal_horizontal_css' );
// Disable card funding source from PayPal SDK URL
function citation_paypal_disable_card_funding( $disabled, $is_single ) {
    if ( ! $is_single ) {
        return $disabled;
    }
    if ( ! in_array( 'card', $disabled, true ) ) {
        $disabled[] = 'card';
    }
    return $disabled;
}
add_filter(
    'wpforms_integrations_paypal_commerce_frontend_get_disabled_funding_sources',
    'citation_paypal_disable_card_funding',
    10,
    2
);
// Hide "Powered by PayPal" element via MutationObserver
function citation_hide_paypal_powered_by() {
    ?>
    <script type="text/javascript">
    jQuery(function($) {
        var observer = new MutationObserver(function() {
            document.querySelectorAll('.paypal-powered-by').forEach(function(el) {
                el.style.setProperty('display', 'none', 'important');
            });
        });
        observer.observe(document.body, { childList: true, subtree: true });
    });
    </script>
    <?php
}
add_action( 'wpforms_wp_footer_end', 'citation_hide_paypal_powered_by', 30 );

Comments

Add a Comment