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

标签 php wordpress woocommerce checkout hook-woocommerce

我对更改 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/

相关文章:

woocommerce - 为产品过滤器设置永久链接

javascript - 如何通过超文本链接调用php函数

php - Cakephp 3 在 frozentime 对象中给出日期和时间字段

javascript - 将 WordPress 帖子 ID 传递到另一个页面

wordpress - WooCommerce 变体作为单选按钮

php - WooCommerce:按产品属性术语过滤管理订单

javascript - 当输入 ="file"时,如何获得预选输入?

javascript - 我该如何才能使我的 API 只能通过我的应用程序(Javascript 和 PHP)访问?

php - 使用 nginx 的 wordpress 空白页面

linux - Postfix 电子邮件转发