首页 > 解决方案 > 如何在 WooCommerce 结帐中更改贝宝的下单按钮文本

问题描述

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

结帐页面将通过 update_checkout 事件重新加载表单,因此 place_order 文本将变回原始文本 'proceed to Paypal'。

我尝试使用 Jquery 和函数挂钩来更改文本,但仍会改回来。

功能 woo_custom_order_button_text() {
    return __( '你的新按钮文本在这里', 'woocommerce' );
}

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

标签: phpwordpresswoocommercecheckouthook-woocommerce

解决方案


要在 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 文件中。测试和工作。


推荐阅读