حذف گزینه حمل ونقل در صورت دریافت حضوری در ووکامرس

اگر شما فروش حضوری دارید و در کنارش سایت اینترنتی هم دارید میتوانید گزینه ای با عنوان “خرید حضوری ” اضافه نمایید تا هنگام خرید با انتخاب ان گزینه دیگر هزینه حمل و نقل ندهد.
برای حذف گزینه حمل ونقل در ووکامرس کافیست کد زیر را در functions.php قرار دهید
add_action( 'woocommerce_after_checkout_form', 'a4fran3_disable_shipping_local_pickup' );
function a4fran3_disable_shipping_local_pickup( $available_gateways ) {
global $woocommerce;
// Part 1: Hide shipping based on the static choice @ Cart
// Note: "#customer_details .col-2" strictly depends on your theme
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping_no_ajax = $chosen_methods[0];
if ( 0 === strpos( $chosen_shipping_no_ajax, 'local_pickup' ) ) {
?>
<script type="text/javascript">
jQuery('#customer_details .col-2').fadeOut();
</script>
<?php
}
// Part 2: Hide shipping based on the dynamic choice @ Checkout
// Note: "#customer_details .col-2" 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-2').fadeOut();
} else {
jQuery('#customer_details .col-2').fadeIn();
}
});
</script>
<?php
}
نتیجه کد بالا :












