首页 文章

在Woocommerce中更改默认选定的支付网关

提问于
浏览
1

我在Woocommerce结帐页面中有两个不同的支付网关(条带和银行转帐) . 但默认情况下,“银行转帐”(bacs)始终是自动选中的 .

以下是我的结帐页面上支付网关的屏幕截图:

enter image description here

我想改变它并自动选择条带支付网关intead .

我该怎么做? . 任何帮助表示赞赏 .

3 回答

  • 1

    您可以根据需要重新安排支付网关(在您的情况下,信用卡(Stripe),然后是直接银行转帐),以便每个新会话始终选择最高的一个 .

    WooCommerce会自动将当前选择的付款方式(例如直接银行转帐)保存到当前会话中,当您重新加载页面时,将选择该付款方式而不是默认付款方式 . 您可以在私有窗口浏览器中测试它 .

  • 0

    您可以尝试添加以下代码,以更改结帐页面上的默认支付网关 . 您必须在此代码中定义默认的所需支付网关ID:

    add_action( 'woocommerce_before_checkout_form', 'action_before_checkout_form' );
    function action_before_checkout_form(){
        // HERE define the default payment gateway ID
        $default_payment_gateway_id = 'stripe';
    
        WC()->session->set('chosen_payment_method', $default_payment_gateway_id);
    }
    

    代码位于活动子主题(或活动主题)的function.php文件中 . 经过测试和工作 .

    您现在将始终将Stripe作为默认值:

    enter image description here


    要获取 Stripe 所需的支付网关ID,请进入Woocommerce>设置>结帐并在 "Gateway ID" column 中找到它,如此屏幕截图所示:

    enter image description here

  • 0

    感谢您的回复@LoicTheAztec

    我把你的下面的代码放在我的孩子主题的function.php中 .

    add_action( 'woocommerce_before_checkout_form', 'action_before_checkout_form' );
    
    function action_before_checkout_form(){
    
        // HERE define the default payment gateway ID
        $default_payment_gateway_id = 'stripe';
    
        WC()->session->set('chosen_payment_method', $default_payment_gateway_id);
    }
    

    Here is the image where stripe gateway id is stripe

    但是,它仍然是默认选择银行转帐 . 我无法理解为什么它不适合我 .

相关问题