woocommerce / woocommerce-gateway-paypal-express-checkout

58 stars 65 forks source link

Smart button position on cart page #803

Closed lamdd1345 closed 4 years ago

lamdd1345 commented 4 years ago

I want to place the smart paypal button top of the proceed to checkout button on cart page, how can I change the code to make it possible? It's now on the bottom of the "proceed to checkout" button.

jorgeatorres commented 4 years ago

Hi @lamdd1345!

Thanks for reaching out. We don't currently have a setting or option that would allow you to do this. To achieve this, you could write some custom PHP or JavaScript code. While we don't provide support for customizations, if you're comfortable editing your theme's functions.php file or adding custom code to your site, something along the following lines should do the trick:

<?php
add_action( 'woocommerce_proceed_to_checkout', function() {
    if ( ! function_exists( 'wc_gateway_ppec' ) || ! has_action( current_action(), 'woocommerce_button_proceed_to_checkout' ) ) {
        return;
    }

    remove_action( current_action(), 'woocommerce_button_proceed_to_checkout', 20 );
    remove_action( current_action(), array( wc_gateway_ppec()->cart, 'display_paypal_button' ), 20 );
    wc_gateway_ppec()->cart->display_paypal_button();
    add_action( current_action(), 'woocommerce_button_proceed_to_checkout', 20 );
}, 10 );

Use at your own risk.

lamdd1345 commented 4 years ago

Thanks! It really works!!