// Hook to restrict shipping based on product and destination postcode
add_filter('woocommerce_package_rates', 'restrict_shipping_by_product_and_postcode', 10, 2);
function restrict_shipping_by_product_and_postcode($rates, $package) {
// Replace '123456' with the postcode of Lucknow
$lucknow_postcode = '226022';
// Check if the destination postcode is different from Lucknow
if ($package['destination']['postcode'] != $lucknow_postcode) {
// Check if there are restricted products in the cart
$restricted_products = array(9651); // Replace with the IDs of the restricted products
foreach ($package['contents'] as $item_id => $values) {
$product_id = $values['product_id'];
if (in_array($product_id, $restricted_products)) {
// If any restricted product is found, unset all shipping methods
$rates = array();
break;
}
}
}
return $rates;
}{"id":720,"date":"2017-07-24T20:39:48","date_gmt":"2017-07-24T20:39:48","guid":{"rendered":"http:\/\/ramasrey.com\/?page_id=720"},"modified":"2022-11-14T23:26:58","modified_gmt":"2022-11-14T17:56:58","slug":"about-us","status":"publish","type":"page","link":"https:\/\/www.ramasrey.com\/about-us\/","title":{"rendered":"About Us"},"content":{"rendered":"\n