Php 选择3不需要付款方式
选择时不需要付款方式。也就是说,将签出页面上的“选择”更改为“复选框”。即使未选择付款方式,也可以下单 我怀疑这是不够的,因为这是可能的,如果您不选择付款方式,它将导致错误或问题 因此,我想添加创建订单的功能,而无需选择付款方式。因此,系统应理解,对于订单,有必要分配一个状态,例如“等待”Php 选择3不需要付款方式,php,wordpress,checkbox,woocommerce,checkout,Php,Wordpress,Checkbox,Woocommerce,Checkout,选择时不需要付款方式。也就是说,将签出页面上的“选择”更改为“复选框”。即使未选择付款方式,也可以下单 我怀疑这是不够的,因为这是可能的,如果您不选择付款方式,它将导致错误或问题 因此,我想添加创建订单的功能,而无需选择付款方式。因此,系统应理解,对于订单,有必要分配一个状态,例如“等待” wp content\plugins\woocommerce\templates\checkout\payment-method.php 更新:首先,您需要一个自定义支付网关: 你可以下载插件,安装并激活它
wp content\plugins\woocommerce\templates\checkout\payment-method.php
更新:首先,您需要一个自定义支付网关:
你可以下载插件,安装并激活它
完成后,您将添加以下代码。它将隐藏此“自定义”付款方式,并使其在结账页面上默认选中
一些jQuery代码将允许在您现有的支付网关和这个隐藏的“自定义”网关之间切换
守则:
// set "custom" payment method as default on checkou and hide it
add_action( 'woocommerce_before_checkout_form', 'set_custom_payment_method_as_default_and_hide_it' );
function set_custom_payment_method_as_default_and_hide_it(){
// Set "custom" payment method as default
WC()->session->set('chosen_payment_method', 'custom');
// Hide this "Custom" payment method
?>
<style>
ul.wc_payment_methods > li.payment_method_custom { display: none !important; }
</style>
<?php
}
// switch between your existing payment gateways and the "custom" one
add_action( 'wp_footer', 'auto_switch_payment_methods' );
function auto_switch_payment_methods(){
// Only on checkout page
if ( ! is_checkout() ) return;
// jQuery code
?>
<script type="text/javascript">
jQuery(function($){
var a = 'form.checkout', b = 'input[name="payment_method"]', c = 'input#payment_method_custom';
$(a).on( 'click', b, function() {
if( ! $(c).is(':checked') && $(this).hasClass('on') ) {
$(c).prop("checked", true);
$(this).removeClass('on');
$('div.payment_box').each( function(){
$(this).hide('fast');
});
} else if( ! $(c).is(':checked') && ! $(this).hasClass('on') ) {
$(b).each( function(){
$(this).removeClass('on');
});
$(this).addClass('on')
}
});
});
</script>
<?php
}
//在checkou上将“自定义”付款方式设置为默认,并将其隐藏
添加操作('woocommerce\u before\u checkout\u form','set\u custom\u payment\u method\u as\u default\u和\u hide\u it');
函数集\自定义\付款\方法\作为\默认\和\隐藏\ it(){
//将“自定义”付款方式设置为默认方式
WC()->session->set('selected_payment_method','custom');
//隐藏此“自定义”付款方式
?>
ul.wc_payment_methods>li.payment_methods_custom{显示:无!重要;}
jQuery(函数($){
变量a='form.checkout',b='input[name=“payment_method”]',c='input#payment_method_custom';
$(a).on('click',b,function(){
if(!$(c).is(':checked')&&$(this.hasClass('on')){
$(c).道具(“选中”,为真);
$(this.removeClass('on');
$('div.payment_box')。每个(函数(){
$(this.hide('fast');
});
}如果(!$(c).is(':checked')&&&!$(this.hasClass('on')){
$(b).每个(函数(){
$(this.removeClass('on');
});
$(this.addClass('on'))
}
});
});
添加过滤器('woocommerce\u cart\u needs\u payment','uuuu return\u false')
请在激活主题的functions.php文件中添加上述过滤器
// set "custom" payment method as default on checkou and hide it
add_action( 'woocommerce_before_checkout_form', 'set_custom_payment_method_as_default_and_hide_it' );
function set_custom_payment_method_as_default_and_hide_it(){
// Set "custom" payment method as default
WC()->session->set('chosen_payment_method', 'custom');
// Hide this "Custom" payment method
?>
<style>
ul.wc_payment_methods > li.payment_method_custom { display: none !important; }
</style>
<?php
}
// switch between your existing payment gateways and the "custom" one
add_action( 'wp_footer', 'auto_switch_payment_methods' );
function auto_switch_payment_methods(){
// Only on checkout page
if ( ! is_checkout() ) return;
// jQuery code
?>
<script type="text/javascript">
jQuery(function($){
var a = 'form.checkout', b = 'input[name="payment_method"]', c = 'input#payment_method_custom';
$(a).on( 'click', b, function() {
if( ! $(c).is(':checked') && $(this).hasClass('on') ) {
$(c).prop("checked", true);
$(this).removeClass('on');
$('div.payment_box').each( function(){
$(this).hide('fast');
});
} else if( ! $(c).is(':checked') && ! $(this).hasClass('on') ) {
$(b).each( function(){
$(this).removeClass('on');
});
$(this).addClass('on')
}
});
});
</script>
<?php
}