{"id":788,"date":"2020-01-28T13:19:37","date_gmt":"2020-01-28T13:19:37","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2020\/01\/28\/delete-cart-price-rules-by-id-in-magento-2\/"},"modified":"2025-05-22T15:05:11","modified_gmt":"2025-05-22T09:35:11","slug":"delete-cart-price-rules-by-id-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/delete-cart-price-rules-by-id-in-magento-2\/","title":{"rendered":"How To Delete Cart Price Rules By ID In Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/experienceleague.adobe.com\/en\/docs\/commerce-admin\/marketing\/promotions\/cart-rules\/price-rules-cart\" target=\"_blank\" rel=\"noreferrer noopener\">Cart price rules<\/a> apply discounts to items in the cart, based on a set of conditions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We&#8217;ve already discussed the steps to <a href=\"https:\/\/meetanshi.com\/blog\/add-magento-shopping-cart-price-rules\/\" target=\"_blank\" rel=\"noreferrer noopener\">add Magento 2 cart price rules<\/a> earlier.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, you may have the business requirement to delete cart price rules based on the season, offer validity, etc. It may even happen that the discount is to be canceled due to some legit rule violation or any other reason.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One of the ways to do so is to <strong>delete cart price rules by ID in Magento 2<\/strong> store as shown below.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method To Delete Cart Price Rules by ID In Magento 2:<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">use Magento\\SalesRule\\Api\\RuleRepositoryInterface;\nuse Exception;\n\nprotected $ruleRepository;\n\npublic function __construct(RuleRepositoryInterface $ruleRepository) {\n    $this->ruleRepository = $ruleRepository;\n}\n\n\n\/\/need to pass rule id\npublic function deleteById($ruleId)\n{\n    try {\n        $salesRule = $this->ruleRepository->deleteById($ruleId);\n    } catch (Exception $e) {\n        \\Magento\\Framework\\App\\ObjectManager::getInstance()->get('Psr\\Log\\LoggerInterface')->info($e->getMessage());\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Follow the above method to remove the discount price rules programmatically by ID in Magento 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Removing the applied cart rules avoids mistakes in discount and incur any loss!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Please share the post via social media for fellow Magento developers to make their tasks easier.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Cart price rules apply discounts to items in the cart, based on a set of conditions. We&#8217;ve already discussed the steps to add Magento 2&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-788","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/788","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=788"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/788\/revisions"}],"predecessor-version":[{"id":15111,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/788\/revisions\/15111"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=788"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=788"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}