0

I'm trying to create a custom payment gateway that is based on a javascript API. The button at checkout has to work like the paypal checkout button works which opens another window but I can't find a way to replace the button. Since the button is loaded by javascript and the html is just a place

add_filter( 'woocommerce_order_button_html', 'custom_order_button_html');
function custom_order_button_html( $button ) {

    // The text of the button
    $order_button_text = __(' order', 'woocommerce');

    // HERE you make changes (Replacing the code of the button):
    $button = '<div id="custom_Checkout_Button"></div>'; 
}

I put this function in function __construct but it doesn't replace.

The scripts are loading appropriately. If I load the script through console its loading fine.

Luis Liz
  • 1,939
  • 4
  • 20
  • 31

2 Answers2

1

When you use add_filter, you'll always need to return the content you would like to filter or modify. Therefore, in your case, the code would look like this below.

add_filter( 'woocommerce_order_button_html', 'custom_order_button_html');
function custom_order_button_html( $button ) {

    // The text of the button
    $order_button_text = __(' order', 'woocommerce');

    // HERE you make changes (Replacing the code of the button):
    $button = '<div id="custom_Checkout_Button"></div>';

    // Return the modified/filtered content
    return $button;
}

You can find more usage examples here.

zkan
  • 641
  • 1
  • 12
  • 27
  • Ok that was one of the problems so now it shows up but flashes and disappears. I'm doing this filter in the constructor and then calling the enqueue of the script. – Luis Liz Mar 19 '20 at 04:20
  • So, i got it to work like I said but, considering my question you had the right answer. Thank you. – Luis Liz Mar 19 '20 at 04:36
0

So what I did was do an on change method linked here

Change Pay button on checkout based on Woocommerce chosen payment method

and used another jquery call to reload the script that I needed and it works like a charm.

If there is a right/better way to do this put it as an answer and I will accept.

Luis Liz
  • 1,939
  • 4
  • 20
  • 31