In this little tutorial, we'll show you how to create a cart rule that only applies if cart products do NOT belong to a certain category. For example, we wish to have a discount of 10% for the entire catalog, but we do not want that discount applied if the products purchased belong to the category HOT SALE (ID 10).

First we create the discount rule as we normally do, and then modify the CartRule.php file.

The file that is responsible for validating the coupons is the classes / CartRule.php, inside it, there is a function called "checkValidity".

What we will do is add our code to the beginning of this function, but for this we can create a file called CartRule.php inside the folder overrides / classes / and create the override, or directly modify the original file in classes / CartRule.php ( If we update PrestaShop the change is lost and we must do it again). There are hundreds of tutorials to do overrides, so we will focus on the function itself.

The only thing we need to change is the category code that prevents the rule from being applied to apply the Voucher. In this case it is 10

Product added to wishlist
Product added to compare.

We use a selection of our own and third-party cookies on the pages of this website: Essential cookies, which are required in order to use the website; functional cookies, which provide better easy of use when using the website; performance cookies, which we use to generate aggregated data on website use and statistics; and marketing cookies, which are used to display relevant content and advertising. If you choose "ACCEPT ALL", you consent to the use of all cookies. You can accept and reject individual cookie types and revoke your consent for the future at any time under "Settings".