我对更改 place_order 的文本有疑问。
结帐页面会通过 update_checkout 事件重新加载表单,因此 place_order 文本将变回原始文本“proceed to Paypal”。
我试过使用 Jquery 和函数 Hook 来更改文本,但仍然改回来。
function woo_custom_order_button_text() { return __( 'Your new button text here', 'woocommerce' ); }
如何在不禁用 update_checkout 事件的情况下更改#place_order 的文本?
最佳答案
要在选择了 Paypal 支付网关时更改下订单按钮文本,请使用以下命令:
add_filter( 'gettext', 'change_checkout_paypal_pay_button_text', 10, 3 );
function change_checkout_paypal_pay_button_text( $translated_text, $text, $domain ) {
if( 'Proceed to PayPal' === $text ) {
$translated_text = __('Your custom text', $domain); // <== Here the replacement txt
}
return $translated_text;
}
代码进入事件子主题(或事件主题)的 functions.php 文件。经过测试并有效。
现在要更改其他支付网关的下订单文本,您还需要使用以下内容:
add_filter( 'woocommerce_order_button_text', 'custom_checkout_place_order_text' );
function custom_checkout_place_order_text( $button_text ) {
return __( 'Your custom text here', 'woocommerce' ); // <== custom text Here
}
代码进入事件子主题(或事件主题)的 functions.php 文件。经过测试并有效。
关于php - 如何在 WooCommerce 结帐中更改 Paypal 的下单按钮文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62486389/