duanmeng3573 2018-03-21 11:50
浏览 408
已采纳

根据Woocommerce选择的付款方式,在结账时更改付款按钮

Hi Anyone knows how to change Pay button on checkout based on chosen payment method? I found something but I don't know if I could turn it into a snippet in function.php? Thank you.

    public function __construct() {
    $this->id = 'ry_ecpay_atm';
    $this->has_fields = false;
    $this->order_button_text = __('Pay via ATM', RY_WT::$textdomain);
    $this->method_title = __('ECPay ATM', RY_WT::$textdomain);
    $this->method_description = '';
  • 写回答

3条回答 默认 最新

  • drqvsx1228 2018-03-21 13:58
    关注

    This can be done with the following code (where you will set your payment gateway IDs and the corresponding desired button text):

    add_filter('woocommerce_order_button_text', 'custom_order_button_text' );
    function custom_order_button_text( $order_button_text ) {
        $default = __( 'Place order', 'woocommerce' ); // If needed
        // Get the chosen payment gateway (dynamically)
        $chosen_payment_method = WC()->session->get('chosen_payment_method');
    
        // Set your payment gateways IDs in EACH "IF" statement
        if( $chosen_payment_method == 'bacs'){
            // HERE set your custom button text
            $order_button_text = __( 'Bank wire payment', 'woocommerce' ); 
        } elseif( $chosen_payment_method == 'ry_ecpay_atm'){
            // HERE set your custom button text
            $order_button_text = __( 'Place order via ECPay', 'woocommerce' ); 
        }
        // jQuery code: Make dynamic text button "on change" event ?>
        <script type="text/javascript">
        (function($){
            $('form.checkout').on( 'change', 'input[name^="payment_method"]', function() {
                var t = { updateTimer: !1,  dirtyInput: !1,
                    reset_update_checkout_timer: function() {
                        clearTimeout(t.updateTimer)
                    },  trigger_update_checkout: function() {
                        t.reset_update_checkout_timer(), t.dirtyInput = !1,
                        $(document.body).trigger("update_checkout")
                    }
                };
                t.trigger_update_checkout();
            });
        })(jQuery);
        </script><?php
    
        return $order_button_text;
    }
    

    Code goes in function.php file of your active child theme (or theme). Tested and works.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的