In WooCommerce, there is no Plugin by which I can restrict some products can being delivered in some specific Zip Code/PIN code. It means, suppose I have 100 products in my store. Out of them, 10 products will be delivered in only 1 postcode. The rest of the products will be delivered across the country.
I am very new to coding. Please guide how can we do that in functions.php.
add_filter( 'woocommerce_available_payment_gateways' , 'hide_payment_gateway', 20, 1);
function hide_payment_gateway( $gateways ){
//change whatever amount you want
if( WC()->checkout->zipcode ≠ 713102 ){
// then unset the 'cod' key (cod is the unique id of COD Gateway)
unset( $gateways['cod'] );
add_action( 'woocommerce_review_order_before_payment', 'COD_exceed_amount_before_paying_notice' );
}
return $gateways;
}
function COD_exceed_amount_before_paying_notice() {
wc_print_notice( __( 'delivery not available', 'woocommerce' ), 'notice' );
}
I got some errors on this code. I need to hide shipping or payment gateways for some products for some product IDs.
Your code is outdated, unadapted and with some mistakes. Try the following instead:
Code goes in functions.php file of your child theme (or in a plugin). Tested and works.