WooCommerce Payments Gateway标题的自定义文本
我试图将WooCommerce付款的标签从“流行付款方式”更改为结帐页面上的其他内容。
我将此片段添加到儿童主题的 function.php 中
add_filter( 'woocommerce_gateway_title', 'change_payment_gateway_title', 100, 2 );
function change_payment_gateway_title( $title, $payment_id ){
if( $payment_id === 'woocommerce_payments' ) {
$title = __("custom text", "woocommerce");
}
return $title;
}
,
add_filter( 'woocommerce_gateway_title', 'change_payment_gateway_title' );
function change_payment_gateway_title( $payment_id ){
return str_replace( 'Popular payment methods', 'custom text', $payment_id );
}
当结帐页面仍在加载时,它们都可以使用一秒钟,但标题跳回原始文本(“流行”付款方式”)页面完成加载后。他们可以在其他付款方式上没有任何问题。
我的代码有什么问题吗?
I was trying to change the label of WooCommerce Payments from "Popular payment methods" to something else on the checkout page.
I added this snippet to functions.php of the child theme
add_filter( 'woocommerce_gateway_title', 'change_payment_gateway_title', 100, 2 );
function change_payment_gateway_title( $title, $payment_id ){
if( $payment_id === 'woocommerce_payments' ) {
$title = __("custom text", "woocommerce");
}
return $title;
}
and this
add_filter( 'woocommerce_gateway_title', 'change_payment_gateway_title' );
function change_payment_gateway_title( $payment_id ){
return str_replace( 'Popular payment methods', 'custom text', $payment_id );
}
They both work for a fraction of a second when the checkout page is still loading, but the title jumps back to the original text ("Popular payment methods") when the page has finished loading. They work without any problem for other payment methods though.
Is there anything wrong with my code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
恢复的原始文本源自 woocommerce payment 创建的 js 变量“wcpay_config”。它包含在键“checkoutTitle”中并通过 wp_localize_script。
因为我没有找到连接此函数的方法,所以我使用 这个答案 实现一个子类和您的第一个解决方案相结合,实现完全替换:
如果其他插件停止工作,另请参阅此答案。
The original text getting restored originates from the js variable "wcpay_config" that is created by woocommerce payments. It is contained in the key "checkoutTitle" and passed through wp_localize_script.
Because I didn't find a way to hook into this function I used this answer implementing a subclass and your first solution combined, to achieve a full replacement:
Also take a look at this answer, if other plugins stop working.
什么是$ gateway_id,从哪里得到它?我认为最简单的方法是使用此代码snippet < /a>在WooCommerce设置中添加付款网关ID列。
What is $gateway_id and where to get it? I think the easiest way is to use this code snippet which adds a payment gateway ID column in WooCommerce settings.