Introduction to developer guide for addons
The purpose of this developer guide for addons is to show how to add your own discount to the Conditional Discounts for WooCommerce plugin. It is important to understand the use or operation of the Conditional Discounts for WooCommerce plugin before reading and practicalizing this documentation.
Before starting it is also essential to define what a hook is. In the WordPress ecosystem, a hook is a means of modifying and/or interacting with another code at a specific time. There are two types of hooks: actions that allow you to add data or modify the way WordPress works; and filters that allow you to modify the data (variables) of specific functions.
The Conditional Discounts for WooCommerce plugin contains several hooks which you can add to, or manipulate, to create your own discounts. We are going to study them (filters in this case) in the following order:
- wad_get_discounts_conditions
- wad_fields_values_match
- Wad_operators_fields_match
- wad_is_rule_valid
- wad_get_discounts_conditions: allows you to modify the list of existing conditions or to add new ones.
- wad_fields_values_match: is used to define the list of values available for the condition created using wad_get_discounts_conditions.
- wad_operators_fields_match: allows you to define the type of operator which will be used for your discount.
For example, to verify that a condition belongs to a predefined list we use the operators “IN” and “NOT IN”. In the case of a numerical comparison, we expect the use of operators like superior (>), superior or equal (> =), inferior or equal (<=), inferior or (<), equal ( =) …
These are the default operators of our Conditional Discounts for WooCommerce plugin.
Last updated on March 4, 2023