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.
2
Answers
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.
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.You can find more usage examples here.