在结帐页面上显示付款方式,默认情况下会自动选择第一个付款方式 . 我需要阻止选择,因此WC最初没有选择付款方式 .
到目前为止我尝试了两件事:
来自Chrome控制台的
- jQuery:
jQuery(' . payment_methods input.input-radio') . prop('checked',false);
结果:
[<input id="payment_method_paypal" type="radio" class="input-radio" name="payment_method" value="paypal" data-order_button_text="Proceed to PayPal" checked="checked">,
<input id="payment_method_accountfunds" type="radio" class="input-radio" name="payment_method" value="accountfunds" data-order_button_text>]
- 从payment-method.php Woocommerce模板文件中删除代码:
选中($ gateway-> selected,false);
两者都不起作用 . 怎么做?请问有什么片段或建议吗?
编辑:
还试过这个:
function wpchris_filter_gateways( $gateways ){
global $woocommerce;
foreach ($gateways as $gateway) {
$gateway->chosen = 0;
}
return $gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'wpchris_filter_gateways', 1);
2 回答
好的,搞定了 . 方法如下:
/wp-content/plugins/woocommerce/assets/js/frontend/checkout.js
成:
/wp-content/themes/Your-Theme/woocommerce/js/checkout.js
它应该在第298行附近 . 继续发表评论 .
现在,刷新Checkout页面时不应检查默认付款方式 .
我有同样的问题,我已经解决了这个问题:
用我的子主题checkout-override-js覆盖checkout-js文件 .
然后注释掉以下代码:
行:48:
this.init_payment_methods();
行:58:
行:113:
wc_checkout_form.init_payment_methods();
这将删除默认的付款方式选择 . 您可以使用这些代码使其符合您的要求 .