在 WooCommerce 中更改特定付款方式的结帐提交按钮文本

jho*_*101 2 php wordpress jquery checkout woocommerce

我需要更改order_button_text特定支付网关(在这种情况下为 COD)。

我只能使用以下方法使其全局更改(对于所有支付网关):

add_action( 'woocommerce_after_add_to_cart_button', 'multiple_orders_text' );
function woo_custom_order_button_text() {
    return __( 'Request Shipping Quote', 'woocommerce' );
}
Run Code Online (Sandbox Code Playgroud)

但是发现如果我添加该行

$this->order_button_text  = __( 'Request a Quote', 'woocommerce' );
Run Code Online (Sandbox Code Playgroud)

到其中的setup_properties()方法woocommerce/includes/gateways/cod/class-wc-gateway-cod.php确实有效。

然而,这显然是不好的做法,因为我正在破解一个核心插件文件。

如何在不破解 woocommerce 核心文件的情况下实现这一目标?

Rei*_*gel 7

你可以这样做:

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;
}
Run Code Online (Sandbox Code Playgroud)

雷格加拉德 此代码示例适用于贝宝。有关网关 ID 的参考,请检查WooCoomerce >设置>结帐>网关显示顺序

雷格加拉德