Is there any way to done a backend selected shipping method only display in frontend (checkout)?

Actually expected as


I need to show dynamically selected shipping method alone shown in frontend checkout:

backend setting example


actual result on frontend

  • Please make Enable status only for table rate shipping method for your front-end website/store – Rajesh Hothi Nov 6 '19 at 13:23
  • not only needed for "Table rate" shipping method and i needed for dynamically selected shipping method shown in frontend – Divya Sekar Nov 6 '19 at 13:29
  • Is that your custom field...? – Ranganathan Nov 6 '19 at 13:31
  • yes specific shipping method is custom field – Divya Sekar Nov 6 '19 at 13:50

Let suppose you know which method is available (using it's code). You need a one plugin:


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <!-- Plugins -->
    <type name="Magento\Shipping\Model\Rate\Result">
        <plugin name="disable_shipping_rates_in_some_case"
                disabled="false" />



namespace Vendor\Module\Model\Plugin\Shipping\Rate\Result;

 * Class GetAllRates
class GetAllRates
     * @param $subject
     * @param $result
     * @return \Magento\Quote\Model\Quote\Address\RateResult\Method[]
    public function afterGetAllRates($subject, $result)
        $availableMethods = [

        /** @var \Magento\Quote\Model\Quote\Address\RateResult\Method[] $result */
         * @var int $key
         * @var \Magento\Quote\Model\Quote\Address\RateResult\Method $rate
        foreach ($result as $key => $rate) {
            $code = $rate->getCarrier() . '_' . $rate->getMethod();
            if (!in_array($code, $availableMethods)) {

        return $result;


cart page result

checkout page result

All you need to update is namespaces and the $availableMethods array. Data in the $availableMethods array must be captured from the backend setting of your module (system configuration setting).


If you need to display an error message for unavailable shipping methods you can use next part of code:

/** @var \Magento\Quote\Model\Quote\Address\RateResult\Error $error */
$error = $this->errorFactory->create();
$error->setErrorMessage(__('Error message here'));
$result[$key] = $error;
  • is there any way return a result with error message like this prnt.sc/q72ard – Divya Sekar Dec 6 '19 at 10:59
  • 1
    @divyasekar Yes, I've add desired part of code to my answer. – Siarhey Uchukhlebau Dec 6 '19 at 11:39
  • thank you so much you saved my time – Divya Sekar Dec 6 '19 at 12:26

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.