我正在尝试创建基于javascript API的自定义支付网关。结帐时的按钮必须像Paypal结帐按钮一样工作,这会打开另一个窗口,但我找不到替换该按钮的方法。由于按钮是由javascript加载的,因此html只是一个地方
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>';
}
我将此函数放在function __construct
中,但它不能代替。
脚本正在正确加载。如果我通过控制台加载脚本,则可以正常加载。
答案 0 :(得分:1)
使用add_filter
时,始终需要返回要过滤或修改的内容。因此,根据您的情况,代码如下所示。
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;
}
您可以找到更多用法示例here。
答案 1 :(得分:0)
所以我要做的是在此处链接的on change方法
Change Pay button on checkout based on Woocommerce chosen payment method
,并使用了另一个jquery调用来重新加载我需要的脚本,它的工作原理很吸引人。
如果有正确/更好的方法来解决这个问题,我将接受。