By default, Magento orders cannot be canceled programmatically on the front end. So if you want to cancel an order for any reason, you must do so either by writing code to do so, which is technically difficult and requires coding skills, or by using a third-party extension such as Cancel Orders extension, which allows you to cancel Magento orders without doing it programmatically. With the extension, customers can cancel orders from the front end on their own, and store administrators can automatically cancel pending purchases after a certain period.
To cancel Magento 2 orders without doing it programmatically follow the steps:
Step 1. Navigate to Stores > Configuration > Amasty Extensions > the Cancel Orders tab to configure the basic settings.
Step 2. Set Yes in the Enabled dropdown to make the extension work.
Step 3. In the Allow for Selected Group(s) section, you need to define customer groups for which order cancellation will be on.
Step 4. Choose orders that can be canceled in the Allowed Order Status(es) section.
Step 5. Select the desired option from the Refund Paid Processing Orders Automatically dropdown:
All items in canceled orders will be returned to stock automatically.
The extension processes requests as follows:
Login and Registration Form