0

Is it possible to move paypal checkout button to another place on the screen?

enter image description here

Right now the paypal button is on regular gateway form, I would like to move it to woocommerce_checkout_before_customer_details action.

I was at first using the filter below, but it refers only to placing order button and not paypal button.

<?php
    echo apply_filters( 'woocommerce_order_button_html', '<button type="submit" class="button alt" name="woocommerce_checkout_place_order" id="place_order" >test</button>' ); // @codingStandardsIgnoreLine 
?>

How to relocate paypal button gateway on checkout page in woocommerce?

2 Answers 2

1

Have you tried this?

E.g. the paypal button function name is woo_custom_paypal_button.

Then add action like this into your function.php or specific plugin:

add_action( 'woocommerce_checkout_before_customer_details', 'woo_custom_paypal_button' );

Or if there's something that's already displayed there, and you might want to remove it, first find the function name and then try like this:

remove_action( 'woocommerce_checkout_before_customer_details', 'woo_function_to_remove' );
add_action( 'woocommerce_checkout_before_customer_details', 'woo_custom_paypal_button');

Update

I tried this code and worked in my case:

add_action( 'wp_loaded', 'x_relocate_paypal_button' );
function x_relocate_paypal_button() {
    $cls = new WC_Gateway_PPEC_With_SPB;
    add_action( 'woocommerce_checkout_before_customer_details', array( $cls, 'display_paypal_button' ), 20 );
}

Just replace the woocommerce_checkout_before_customer_details hook to relocate to another position. You can find more visual hook guide on checkout page on this article.

4
  • Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'woo_custom_paypal_button' not found or invalid function name I'm receiving this error, I can't create my own custom woocommerce paypal button, since I wont be able to connect him to woocommerce (or atleast I don't know how). Commented Oct 29, 2020 at 15:27
  • That error is showing because there is no function for woo_custom_paypal_button. You need to replace woo_custom_paypal_button with the valid function name from the Paypal button plugin you're using. If you don't know, just ask the plugin developer or check the code in the plugin.
    – Walter P.
    Commented Oct 29, 2020 at 16:04
  • Basically it's made by woocommerce docs.woocommerce.com/document/paypal-express-checkout - But I can't see any developer related to my topic information in the docs. Commented Oct 29, 2020 at 16:10
  • I have updated my previous answer. Please test it.
    – Walter P.
    Commented Oct 29, 2020 at 17:16
0

This worked for me and moved the button into the review order div:

 add_filter('woocommerce_paypal_payments_checkout_button_renderer_hook', function() {
    return 'woocommerce_review_order_after_submit';
});

https://github.com/woocommerce/woocommerce-paypal-payments/wiki/Actions-and-Filters#change-button-placement-via-render-hooks

https://www.businessbloomer.com/woocommerce-visual-hook-guide-checkout-page/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.