2017-08-17 6 views
1

特定の支払いゲートウェイ(この場合はCOD)のorder_button_textを変更する必要があります。WooCommerceの特定のお支払い方法のチェックアウト送信ボタンテキストを変更

私はそれが使用して(すべての支払いゲートウェイのための)グローバルに変更してもらうことができます:

add_action('woocommerce_after_add_to_cart_button', 'multiple_orders_text'); 
function woo_custom_order_button_text() { 
    return __('Request Shipping Quote', 'woocommerce'); 
} 

をしかし、私はwoocommerce/includes/gateways/cod/class-wc-gateway-cod.phpsetup_properties()方法にそれをライン

$this->order_button_text = __('Request a Quote', 'woocommerce'); 

を追加する場合ことを発見しました動作します。

しかし、これはコアプラグインファイルをハッキングしているので、明らかに悪いことです。

woocommerceのコアファイルをハッキングしないでこれを実現するにはどうすればよいですか?

答えて

3

で動作します:

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; 
} 

reigelgallarde.me このコード例は、PayPalのためのものです。ゲートウェイIDの参照については、WooCoomerce>設定>アウト>ゲートウェイの表示順序

reigelgallarde.me

+0

感謝の負荷を確認してください、それは働きました!最初に配列キーが存在するかどうかを調べるために小さな微調整を行いました。そうでなければエラーがスローされます: 'if(array_key_exists(" paypal "、$ available_gateways)){$ available_gateways ['paypal'] - > order_button_text = __( ' Paypal '、' woocommerce '); } ' 私がこのソリューションがレンダリングサイクルの前に動作するのが好きなので、受け入れられた答えとしてHaceが選択されました。 – jhob101

+0

ahhはい..私の回答を更新します – Reigel

+0

副次的な質問として、これらの解決策についてはどこで知りますか?特に、私は幾分間違った方法で解決策を探し回ってしまったように見えます。 – jhob101

1

(それはクライアント側のライブイベントだから)ここでは主にjQueryのを使用して、の浮きカスタム関数とwoocommerce_review_order_before_paymentアクションフックを使用して、それを行うためのクリーンな方法です:

add_action('woocommerce_review_order_before_payment', 'customizing_checkout_button', 10, 0); 
function customizing_checkout_button(){ 

    $text1 = __('Place order', 'woocommerce'); 
    $text2 = __('Request a Quote', 'woocommerce'); 

    ?> 
    <script> 
     jQuery(function($){ 

      // 1. Initialising once loaded 
      if($('input[name^="payment_method"]:checked').val() == 'cod') 
       $('input[name^="woocommerce_checkout_place_order"]').val('<?php echo $text2; ?>'); 
      else 
       $('input[name^="woocommerce_checkout_place_order"]').val('<?php echo $text1; ?>'); 

      // 2. Live event detection:When payment method is changed 
      $('form.checkout').on('change', 'input[name^="payment_method"]', function() { 
       var choosenPaymentMethod = $('input[name^="payment_method"]:checked').val(); // Chosen 

       if(choosenPaymentMethod == 'cod') 
        $('input[name^="woocommerce_checkout_place_order"]').val('<?php echo $text2; ?>'); 
       else 
        $('input[name^="woocommerce_checkout_place_order"]').val('<?php echo $text1; ?>'); 
      }); 
     }); 
    </script> 
    <?php 
} 

コードはあなたのアクティブな子テーマ(またはテーマ)のfunction.phpファイル、またはすべてのプラグインファイルにあります。

あなたはこのようにそれを行うことができますテストされたとWooCommerce 3+

関連する問題