问题描述
我需要为特定的支付网关(在这种情况下为COD)更改order_button_text
.
I need to change the order_button_text
for a specific payment gateway (COD in this case).
我只能使用以下方法(对于所有付款网关)进行全局更改:
I could only get it to change globally (for all payment gateways) using:
add_action( 'woocommerce_after_add_to_cart_button', 'multiple_orders_text' );
function woo_custom_order_button_text() {
return __( 'Request Shipping Quote', 'woocommerce' );
}
但是发现如果我添加行
$this->order_button_text = __( 'Request a Quote', 'woocommerce' );
对于woocommerce/includes/gateways/cod/class-wc-gateway-cod.php
中的setup_properties()
方法确实有效.
to the setup_properties()
method in woocommerce/includes/gateways/cod/class-wc-gateway-cod.php
it does work.
但是,这显然是错误的做法,因为我正在入侵核心插件文件.
However this is clearly bad practice as I'm hacking a core plugin file.
如何在不破解woocommerce核心文件的情况下实现这一目标?
How can I achieve this without hacking a woocommerce core file?
推荐答案
您可以这样做:
add_filter( 'woocommerce_available_payment_gateways', 'woocommerce_available_payment_gateways' );
function woocommerce_available_payment_gateways( $available_gateways ) {
if (! is_checkout() ) return $available_gateways; // stop doing anything if we're not on checkout page.
if (array_key_exists('paypal',$available_gateways)) {
// Gateway ID for Paypal is 'paypal'.
$available_gateways['paypal']->order_button_text = __( 'Request a Quote', 'woocommerce' );
}
return $available_gateways;
}
此代码示例适用于Paypal.有关网关ID的参考,请检查 WooCoomerce > 设置> 结帐> 网关显示顺序
This code example is for paypal. For reference of the gateway IDs, please check WooCoomerce > Settings > Checkout > Gateway display order
这篇关于更改WooCommerce中特定付款方式的结帐提交按钮文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!