2 回答
TA贡献1789条经验 获得超10个赞
将类分配给 b、d、f、z 和 s 可能会更简单。如果您已经定义了“a”,那么您可以执行以下操作:
$(a).change(function() {
if ($(a).val() == 'pickup') {
$(".special").hide();
} else {
$(".special").show();
}
});
TA贡献1811条经验 获得超6个赞
尝试使用以下代码,当交付方式为本地取货时,该代码会在任何地方禁用提交表单。
您应该将 (28): "local_pickup:28" 替换为您的送货方式的 ID。
add_action( 'woocommerce_after_checkout_form', 'disable_shipping_local_pickup' );
function disable_shipping_local_pickup( $available_gateways ) {
// Part 1: Hide shipping based on the static choice @ Cart
// Note: "#customer_details .woocommerce-shipping-fields" (formerly "#customer_details .col-2", but was too broad & was also hidding additional fields that aren't shipping related that just happened to be in the second column) 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:28' ) ) {
?>
<script type="text/javascript">
jQuery('#customer_details .woocommerce-shipping-fields').fadeOut();
</script>
<?php
}
// Part 2: Hide shipping based on the dynamic choice @ Checkout
// Note: "#customer_details .woocommerce-shipping-fields" (formerly "#customer_details .col-2", but was too broad & was also hidding additional fields that aren't shipping related that just happened to be in the second column) strictly depends on your theme
?>
<script type="text/javascript">
jQuery('form.checkout').on('change','input[name^="shipping_method"]',function() {
var val = jQuery('input[name^="shipping_method"]:checked').val(); // If it changed, then it must be the radio options so check the one that's selected
if (val.match("^local_pickup:28")) {
jQuery('#customer_details .woocommerce-shipping-fields').fadeOut();
} else {
jQuery('#customer_details .woocommerce-shipping-fields').fadeIn();
}
});
// Also check if the zipcode switched to something where local pickup is the only option (similar to what's done in part 1 above, but happen based on what's currently being entered on the page [watch via ajaxComplete since the options that are available/selected might not be present when the zipcode change happens & it needs to load those in via AJAX])
jQuery(document).ajaxComplete(function(){
if(jQuery('input[name^="shipping_method"]').attr('type') === 'hidden'){ // There's only one option so check the hidden input field with the value
var val = jQuery('input[name^="shipping_method"]').val();
}else{ // Otherwise, it must be the radio options so check the one that's selected
var val = jQuery('input[name^="shipping_method"]:checked').val();
}
if (val.match("^local_pickup:28")) {
jQuery('#customer_details .woocommerce-shipping-fields').fadeOut();
} else {
jQuery('#customer_details .woocommerce-shipping-fields').fadeIn();
}
});
</script>
<?php
}
- 2 回答
- 0 关注
- 125 浏览
添加回答
举报