From Magento 2 (http://devdocs.magento.com/guides/v2.1/extension-dev-guide/plugins.html)

Prioritizing plugins

The sortOrder property for plugins determine when their before, after, or around methods get called when several plugins are observing the same method.

The prioritization rules for ordering plugins:

Prior to execution of the observed method, plugins will be executed from lowest to greatest sortOrder.

During each plugin execution, the current plugin’s before method is executed first. After the before plugin is executed, the current plugin’s around method will wrap and execute the next plugin or observed method. Following the execution of the observed method, plugins will be executed from greatest to lowest sortOrder.

During each plugin execution, the current plugin will first finish executing its around method. When the around method is complete, the plugin executes its after method before moving on to the next plugin.

However, I want to stop / remove a process in a function of a third party / custom plugin. So I don't want it runs if a condition broken. It means I don't want the function can run in some situations. So how can I override that function to do that ?

I can create a plugin has a method with lower priority than the method, then it can be run earlier than the method. But as I understand, after my function runs then the function runs too. I can not stop it to run as Magento states.

More details about the function I want to override:

 public function aroundSavePaymentInformation(
        \Magento\Checkout\Model\GuestPaymentInformationManagement $subject,
        \Closure $proceed,
        \Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
        \Magento\Quote\Api\Data\AddressInterface $billingAddress = null
        $orderAttributes = $billingAddress->getOrderAttributes(); => It will be fail if there is no $billingAddress, so I want to add a check to make sure if we have $billingAddress, then the process will be called, if not then return.
        $this->sessionHelper->setOrderAttributesToSession($cartId, $orderAttributes);
        return $proceed($cartId,  $email, $paymentMethod, $billingAddress);

Please suggest some solutions that you may have, I am really appreciate it.

2 Answers 2


If it's third party plugin and you have control over the installation then i think fixing the original issue in that module is the best approach.

If that is not doable for some reason, i remember reading somewhere that you should always call $proceed() in around plugins so other plugins can run. Based on that i would say that if you dont call $proceed, but perform the logic directly in your around plugin, then the problematic plugin wont run.

I haven't tested this, just an idea.


Plugins are just normal classes. You can create plugin for plugin method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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