How to create a rule for specific attributes?
In this example, we'll create a rule to restrict the stock quantity to 12 units for product variations that match the attribute combination of Color: Green, Material: Silk, and Size: Medium.
The steps to create this scenario are below:
- Navigate to the rule creation section in the plugin settings.
- Set the rule status to enabled.
- Assign a title to the rule, such as "Restrict Stock for Green Silk Medium".
- Specify the SKU for the rule else it will auto generate from the title.
- Define the stock quantity to which the rule will apply, for example, 12 units.
- Add any additional notes or details about the rule.
- Optionally, set a low stock threshold to receive alerts when stock levels approach a certain limit.
- If needed, enable the "Limit Product Stock" option to restrict customers from choosing quantities beyond the defined stock quantity.
- Create a new group for the attribute combination.
- Add attributes and terms to the group:
- Attribute: Color, Term: Green
- Attribute: Material, Term: Silk
- Attribute: Size, Term: Medium
- For the created group, set the "Quantity Multiplier" field to 2. This means that if a product variation matches the specified attribute combination, 2 units of stock will be deducted from inventory.
- Save the rule settings.
- The rule is now active and will restrict the stock quantity to 6 units for product variations matching the attribute combination of Color: Green, Material: Silk, and Size: Medium.
Note: Here We have mentioned 6 units as stock because we have added 12 in stock in the rule and 2 as quantity multiplier for attribute and term combination. So in the end, 12/2 = 6 units of this combination can sell.
Now, we can check on the front end side how our product will look like when we apply rules to it.
If we have 4 stocks in the cart (which means our rule will understand 8 quantities as the stock multiplier is 2. e.g., 4 * 2 = 8). Then we add another 4 quantities into the cart then we can get a validation message.
Once we place an order on site it will show as our attribute stock status in the order note in the admin.
Note: As we can see there are 2 rules stocks are decrease. this is because we have matched the same combination in another rule. So our plugin will also update its stock status.