首页 文章

如何通过PHP在Woocommerce中设置付款方式

提问于
浏览
1

我想在Woocommerce网站上通过PHP手动选择付款方式 .

像这样的东西:

$payment_method = 'authorize_net_aim'

然后,当客户点击结账并查看列表付款选项时,将自动选择在PHP中设置的付款方式 . 挑战是woocommerce checkout.js在加载页面后运行ajax . 所以我试过的任何页面内容都会被覆盖 .

我已经查看了WC_Payment_Gateway class但是没有't see how to select a specific gateway using it'的id(即authorize_net_aim) .

1 回答

  • 0

    可以使用以下代码实现该问题的解决方案,即自动选择支付模式 .

    add_action('woocommerce_review_order_before_submit','select_payment_mode_as_defined_here' ); function select_payment_mode_as_defined_here(){ echo '<script>jQuery("#authorize_net_aim").prop("checked", true);</script>'; }

    假设'authorize_net_aim'是无线电选项按钮的id .

    我使用此解决方案选择PayPal方法作为默认值,因此在jQuery()中将id设置为'#payment_method_paypal',它对我有用 .

    Lemme知道它是否也适合你 . 这个答案是否有用 .

相关问题