{"id":335069,"date":"2022-05-20T15:00:41","date_gmt":"2022-05-20T15:00:41","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=335069"},"modified":"2026-02-05T05:42:18","modified_gmt":"2026-02-05T05:42:18","slug":"add-custom-sales-rule-conditions-in-magento-2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/","title":{"rendered":"Add custom sales rule conditions in Magento 2"},"content":{"rendered":"\n<p>Here, we\u2019ll demonstrate how to add custom sales rule conditions in Magento 2, with clear steps and code examples to help you extend your cart rule logic.<\/p>\n\n\n\n<p>We will add custom sales rule conditions in the configuration of the <a href=\"http:\/\/how-to-add-custom-sales-rule-conditions-in-magento-2\">custom module<\/a>.<\/p>\n\n\n\n<p><strong>Sales Rule conditions<\/strong> &#8211; It allows us to create dynamic conditions for the shopping carts.<\/p>\n\n\n\n<p>Example &#8211; I am going to create conditions for the customer groups as It&#8217;s showing in the below images.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"366\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-25T102550.759-1200x366.png\" alt=\"Screenshot-2022-05-25T102550.759\" class=\"wp-image-336764\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-25T102550.759-1200x366.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-25T102550.759-300x91.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-25T102550.759-250x76.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-25T102550.759-768x234.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-25T102550.759.png 1273w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>First of all, we will create an observer that will add our condition.<\/p>\n\n\n\n<p>So we need to create an &#8220;events.xml&#8221; file inside the etc folder and add the below code into the file.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;event name=&quot;salesrule_rule_condition_combine&quot;&gt;\n        &lt;observer name=&quot;customer_groups&quot; instance=&quot;Vendor\\Module\\Observer\\CustomerGroupsObserver&quot; \/&gt;\n&lt;\/event&gt;<\/pre>\n\n\n\n<p>Now, we will create &#8220;CustomerGroupsObserver.php&#8221;&nbsp;inside the observer folder.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">namespace Vendor\\Module\\Observer;\n\n\/**\n * Observer for CustomerGroups\n *\/\nclass CustomerGroupsObserver implements \\Magento\\Framework\\Event\\ObserverInterface\n{\n    \/**\n     * Execute observer.\n     *\n     * @param \\Magento\\Framework\\Event\\Observer $observer\n     * @return $this\n     *\/\n    public function execute(\\Magento\\Framework\\Event\\Observer $observer)\n    {\n        $additional = $observer-&gt;getAdditional();\n        $conditions = (array) $additional-&gt;getConditions();\n\n        $conditions = array_merge_recursive($conditions, &#091;\n            $this-&gt;getCustomerGroupsCondition()\n        ]);\n\n        $additional-&gt;setConditions($conditions);\n        return $this;\n    }\n\n    \/**\n     * Get condition for customer groups.\n     *\n     * @return array\n     *\/\n    private function getCustomerGroupsCondition()\n    {\n        return &#091;\n            &#039;label&#039;=&gt; __(&#039;Customer groups&#039;),\n            &#039;value&#039;=&gt; \\Vendor\\Module\\Model\\Rule\\Condition\\CustomerGroups::class\n        ];\n    }\n}<\/pre>\n\n\n\n<p>Now, we can move on to the logic part which is responsible for our condition.<\/p>\n\n\n\n<p>We need to add the below code into the di.xml.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;type name=&quot;Vendor\\Module\\Model\\Rule\\Condition\\CustomerGroups&quot;&gt;\n        &lt;arguments&gt;\n            &lt;argument name=&quot;data&quot; xsi:type=&quot;array&quot;&gt;\n                &lt;item name=&quot;form_name&quot; xsi:type=&quot;string&quot;&gt;sales_rule_form&lt;\/item&gt;\n            &lt;\/argument&gt;\n        &lt;\/arguments&gt;\n&lt;\/type&gt;<\/pre>\n\n\n\n<p>At Last, We will create one more file named &#8220;CustomerGroups.php&#8221;.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">namespace Vendor\\Module\\Model\\Rule\\Condition;\n\n\/**\n * Customer Groups model\n *\/\nclass CustomerGroups extends \\Magento\\Rule\\Model\\Condition\\AbstractCondition\n{\n    \/**\n     * @var \\Magento\\Customer\\Model\\ResourceModel\\Group\\CollectionFactory\n     *\/\n    protected $groupCollectionFactory;\n\n    \/**\n     * Constructor initialise\n     *\n     * @param \\Magento\\Rule\\Model\\Condition\\Context $context\n     * @param \\Magento\\Customer\\Model\\ResourceModel\\Group\\CollectionFactory $groupCollectionFactory\n     * @param \\Magento\\Framework\\App\\Config\\ScopeConfigInterface $scopeConfig\n     * @param \\Magento\\Framework\\Json\\Helper\\Data $jsonHelper\n     * @param array $data\n     *\/\n    public function __construct(\n        \\Magento\\Rule\\Model\\Condition\\Context $context,\n        \\Magento\\Customer\\Model\\ResourceModel\\Group\\CollectionFactory $groupCollectionFactory,\n        \\Magento\\Framework\\App\\Config\\ScopeConfigInterface $scopeConfig,\n        \\Magento\\Framework\\Json\\Helper\\Data $jsonHelper,\n        array $data = &#091;]\n    ) {\n        parent::__construct($context, $data);\n        $this-&gt;_groupCollectionFactory = $groupCollectionFactory;\n        $this-&gt;scopeConfig = $scopeConfig;\n        $this-&gt;_json = $jsonHelper;\n    }\n\n    \/**\n     * Load attribute options\n     *\n     * @return $this\n     *\/\n    public function loadAttributeOptions()\n    {\n        $this-&gt;setAttributeOption(&#091;\n            &#039;customer_groups&#039; =&gt; __(&#039;Customer groups&#039;)\n        ]);\n        return $this;\n    }\n\n    \/**\n     * Get input type\n     *\n     * @return string\n     *\/\n    public function getInputType()\n    {\n        return &#039;multiselect&#039;;\n    }\n\n    \/**\n     * Get value element type\n     *\n     * @return string\n     *\/\n    public function getValueElementType()\n    {\n        return &#039;multiselect&#039;;\n    }\n\n    \/**\n     * Get value select options\n     *\n     * @return array|mixed\n     *\/\n    public function getValueSelectOptions()\n    {\n        if (!$this-&gt;hasData(&#039;value_select_options&#039;)) {\n            $this-&gt;setData(\n                &#039;value_select_options&#039;,\n                $this-&gt;_groupCollectionFactory-&gt;create()\n                -&gt;addFieldToFilter(&#039;customer_group_id&#039;, &#091;&#039;neq&#039; =&gt; 0])\n                -&gt;loadData()-&gt;toOptionArray()\n            );\n        }\n        return $this-&gt;getData(&#039;value_select_options&#039;);\n    }\n\n    \/**\n     * Validate Customer Group Rule Condition\n     *\n     * @param \\Magento\\Framework\\Model\\AbstractModel $model\n     * @return bool\n     *\/\n    public function validate(\\Magento\\Framework\\Model\\AbstractModel $model)\n    {\n        $currentCustomerGroup = $this-&gt;getCurrentCustomerGroup();\n        $conditions = $this-&gt;getOrderApprovalConditions();\n        \n        foreach ($conditions&#091;&#039;conditions&#039;] as $key =&gt; $value) {\n            if (is_string($key)) {\n                $stringKeys = $key;\n                $attribute  = $conditions&#091;&#039;conditions&#039;]&#091;$stringKeys]&#091;&#039;attribute&#039;];\n                if ($attribute == &#039;customer_groups&#039;) {\n                    $attributeValue  = $conditions&#091;&#039;conditions&#039;]&#091;$stringKeys]&#091;&#039;value&#039;];\n                }\n            }\n        }\n        $validateGroups = 0;\n        if (in_array($currentCustomerGroup, $attributeValue)) {\n            $validateGroups = 1;\n        }\n        $model-&gt;setData(&#039;customer_groups&#039;, $validateGroups);\n        return parent::validate($model);\n    }\n\n    \/**\n     * Get current Customer group\n     *\n     * @return string\n     *\/\n    public function getCurrentCustomerGroup()\n    {\n        if ($this-&gt;customerSession-&gt;isLoggedIn()) {\n            $customerGroup = $this-&gt;customerSession-&gt;getCustomer()-&gt;getGroupId();\n            return $customerGroup;\n        }\n    }\n    \n   \/**\n     * Get order approval conditions\n     *\n     * @return array|boolean\n     *\/\n    public function getOrderApprovalConditions()\n    {\n        $conditions =  $this-&gt;scopeConfig-&gt;getValue(\n            &quot;order_approval\/settings\/condition&quot;,\n            \\Magento\\Store\\Model\\ScopeInterface::SCOPE_STORE\n        );\n        \n        if ($conditions) {\n            return $this-&gt;_json-&gt;jsonDecode($conditions);\n        }\n\n        return false;\n    }\n}<\/pre>\n\n\n\n<p>After this, Clear the cache and check. The condition will be added successfully which looks like the below-added image.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"589\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-25T102529.129-1200x589.png\" alt=\"Screenshot-2022-05-25T102529.129\" class=\"wp-image-336765\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-25T102529.129-1200x589.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-25T102529.129-300x147.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-25T102529.129-250x123.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-25T102529.129-768x377.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-25T102529.129.png 1271w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>That\u2019s all about the custom <a href=\"https:\/\/docs.magento.com\/user-guide\/v2.3\/sales-channels\/amazon\/pricing-rule-conditions.html\">sales rule condition<\/a>. Hope this will be helpful.<\/p>\n\n\n\n<p>If you have any questions please comment below, and we will try to respond to you. Thanks! \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here, we\u2019ll demonstrate how to add custom sales rule conditions in Magento 2, with clear steps and code examples to help you extend your cart rule logic. We will add custom sales rule conditions in the configuration of the custom module. Sales Rule conditions &#8211; It allows us to create dynamic conditions for the shopping <a href=\"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":430,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9121],"tags":[12794,12792,2070,12793],"class_list":["post-335069","post","type-post","status-publish","format-standard","hentry","category-magento-2","tag-custom-cart-rules","tag-custom-sales-rule-magento-2","tag-magento2","tag-sales-rule-conditions"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Add Custom Sales Rule Conditions in Magento 2<\/title>\n<meta name=\"description\" content=\"we will add custom sales rule conditions in the custom module. It allows us to create dynamic conditions for the shopping carts.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Add Custom Sales Rule Conditions in Magento 2\" \/>\n<meta property=\"og:description\" content=\"we will add custom sales rule conditions in the custom module. It allows us to create dynamic conditions for the shopping carts.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-05-20T15:00:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-05T05:42:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-25T102550.759-1200x366.png\" \/>\n<meta name=\"author\" content=\"Shweta Singh\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Shweta Singh\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/\"},\"author\":{\"name\":\"Shweta Singh\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/2aa9e6c8f634365b94451ac7a636a444\"},\"headline\":\"Add custom sales rule conditions in Magento 2\",\"datePublished\":\"2022-05-20T15:00:41+00:00\",\"dateModified\":\"2026-02-05T05:42:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/\"},\"wordCount\":214,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-25T102550.759-1200x366.png\",\"keywords\":[\"custom cart rules\",\"custom sales rule Magento 2\",\"Magento2\",\"sales rule conditions\"],\"articleSection\":[\"Magento 2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/\",\"url\":\"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/\",\"name\":\"Add Custom Sales Rule Conditions in Magento 2\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-25T102550.759-1200x366.png\",\"datePublished\":\"2022-05-20T15:00:41+00:00\",\"dateModified\":\"2026-02-05T05:42:18+00:00\",\"description\":\"we will add custom sales rule conditions in the custom module. It allows us to create dynamic conditions for the shopping carts.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-25T102550.759.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-25T102550.759.png\",\"width\":1273,\"height\":388,\"caption\":\"Screenshot-2022-05-25T102550.759\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Add custom sales rule conditions in Magento 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/2aa9e6c8f634365b94451ac7a636a444\",\"name\":\"Shweta Singh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/51b8ea403cd7931cc8ef43d9b80e04e02143fd85bae4fe4ff866790408fb82d0?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/51b8ea403cd7931cc8ef43d9b80e04e02143fd85bae4fe4ff866790408fb82d0?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"caption\":\"Shweta Singh\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/shweta-singh342\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Add Custom Sales Rule Conditions in Magento 2","description":"we will add custom sales rule conditions in the custom module. It allows us to create dynamic conditions for the shopping carts.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/","og_locale":"en_US","og_type":"article","og_title":"Add Custom Sales Rule Conditions in Magento 2","og_description":"we will add custom sales rule conditions in the custom module. It allows us to create dynamic conditions for the shopping carts.","og_url":"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2022-05-20T15:00:41+00:00","article_modified_time":"2026-02-05T05:42:18+00:00","og_image":[{"url":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-25T102550.759-1200x366.png","type":"","width":"","height":""}],"author":"Shweta Singh","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Shweta Singh","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/"},"author":{"name":"Shweta Singh","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/2aa9e6c8f634365b94451ac7a636a444"},"headline":"Add custom sales rule conditions in Magento 2","datePublished":"2022-05-20T15:00:41+00:00","dateModified":"2026-02-05T05:42:18+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/"},"wordCount":214,"commentCount":2,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-25T102550.759-1200x366.png","keywords":["custom cart rules","custom sales rule Magento 2","Magento2","sales rule conditions"],"articleSection":["Magento 2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/","url":"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/","name":"Add Custom Sales Rule Conditions in Magento 2","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-25T102550.759-1200x366.png","datePublished":"2022-05-20T15:00:41+00:00","dateModified":"2026-02-05T05:42:18+00:00","description":"we will add custom sales rule conditions in the custom module. It allows us to create dynamic conditions for the shopping carts.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-25T102550.759.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-25T102550.759.png","width":1273,"height":388,"caption":"Screenshot-2022-05-25T102550.759"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/add-custom-sales-rule-conditions-in-magento-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Add custom sales rule conditions in Magento 2"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/2aa9e6c8f634365b94451ac7a636a444","name":"Shweta Singh","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/51b8ea403cd7931cc8ef43d9b80e04e02143fd85bae4fe4ff866790408fb82d0?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/51b8ea403cd7931cc8ef43d9b80e04e02143fd85bae4fe4ff866790408fb82d0?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","caption":"Shweta Singh"},"url":"https:\/\/webkul.com\/blog\/author\/shweta-singh342\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/335069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/430"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=335069"}],"version-history":[{"count":8,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/335069\/revisions"}],"predecessor-version":[{"id":524958,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/335069\/revisions\/524958"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=335069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=335069"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=335069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}