【发布时间】:2021-08-26 05:48:52
【问题描述】:
我正在使用以下功能根据客户是否选择本地取货来显示/隐藏结帐的送货地址部分。
它可以正常工作,但是运输部分中的某些字段是必需的,因此如果选择本地运输,结帐将不起作用。
如果选择本地取货,有没有办法使这些字段不需要?
add_action( 'woocommerce_after_checkout_form', 'bbloomer_disable_shipping_local_pickup' );
function bbloomer_disable_shipping_local_pickup( $available_gateways ) {
// Part 1: Hide shipping based on the static choice @ Cart
// Note: "#customer_details .col-1" strictly depends on your theme
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];
if ( 0 === strpos( $chosen_shipping, 'local_pickup' ) ) {
?>
<script type="text/javascript">
jQuery('#customer_details .col-1').fadeOut();
</script>
<?php
}
// Part 2: Hide shipping based on the dynamic choice @ Checkout
// Note: "#customer_details .col-1" strictly depends on your theme
?>
<script type="text/javascript">
jQuery('form.checkout').on('change','input[name^="shipping_method"]',function() {
var val = jQuery( this ).val();
if (val.match("^local_pickup")) {
jQuery('#customer_details .col-1').fadeOut();
} else {
jQuery('#customer_details .col-1').fadeIn();
}
});
</script>
<?php
}
【问题讨论】:
标签: php wordpress woocommerce shipping