提问者:小点点

如何在WooCommerce结帐中更改paypal的下单按钮文本


我有一个关于更改place_order文本的问题。

签出页面将通过update_checkout事件重新加载表单,因此place_order文本将变回原始文本‘继续到贝宝’。

我尝试过使用Jquery和function hook来更改文本,但仍然会更改回来。

function woo_custom_order_button_text() {
    return __( 'Your new button text here', 'woocommerce' ); 
}

如何通过不禁用update_checkout事件来更改#PLACE_ORDER的文本?


共1个答案

匿名用户

当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文件中。 经过测试并正常工作。