php - 如何在 WooCommerce 结帐中更改贝宝的下单按钮文本
问题描述
我有一个关于更改 place_order 文本的问题。
结帐页面将通过 update_checkout 事件重新加载表单,因此 place_order 文本将变回原始文本 'proceed to Paypal'。
我尝试使用 Jquery 和函数挂钩来更改文本,但仍会改回来。
功能 woo_custom_order_button_text() { return __( '你的新按钮文本在这里', '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 文件中。测试和工作。
推荐阅读
- ios - 如何从函数内部获取文本字段的文本?
- .net - 使用 DebugDiag 调试挂起 - GC 挂起?
- java - 接受许可后如何运行相机
- javascript - 交替执行功能
- configuration - 如何修改默认的 graphdb.home 目录?
- javascript - 我的按钮不是由 p5js 创建的,我使用 addEventListener "click" 事件和里面的 loop(),但是当我点击那个按钮时循环运行一次
- wordpress - 停用产品的悬停效果,让“数量”和“购买”按钮始终可见
- javascript - 难以将值存储在 const 中并保持输入值的状态(不是道具)
- dart - 是否可以使用 .where() 来“断言”一个类型?
- node.js - 如何以json字符串作为值解析json