0

I want to show my custom shipping method based on state/region.

0

Every shipping method class has a method collectRates() and from this method, respective availability, shipping price or rate are managed.

If you will check it's the parameter $request and then you will see that parameter has currently selected shipping address's country id and Region Id, City, postcode.

  • $request->getCountryId() // country id $
  • request->getRegionId() // region id
  • $request->getCity() // city id
  • $request->getPostcode() //postcode id
  • How to get when a customer has no address & customer come first time in the store. – Avinash Sain Apr 20 '18 at 13:11
  • for calculating shipping should have an address which may be the new address or existing shipping address – Amit Bera Apr 20 '18 at 13:31
  • Issue with new address – Avinash Sain Apr 20 '18 at 13:51
  • Can you be more explicit with some example? – Luis Jun 22 '18 at 17:46
0

If you want disable or enable shipping method for example UPS or flatrate based on Region ID then yo need to rewrite class: Magento\Shipping\Model\Shipping in your custom module and add this code in method: collectCarrierRates

    $regionId = $request->getDestRegionId();
    $yourRegionId1 = 569;
    $yourRegionId2 = 583;
    if($regionId == $yourRegionId1 && $carrierCode == "ups"){
        $result = false;
    }

    if($regionId != $yourRegionId2 && $carrierCode == "flatrate"){
        $result = false;
    }

Note: You can take the region id from table: directory_country_region

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.