FacetWP – Conditional Logic
This add-on gives you the ability to toggle facets (and other elements) depending on the conditions you set.
Rulesets
You are going to need to develop a ruleset for every single action that you wish to complete. You can accomplish this by clicking the “Add Ruleset” button, which places an empty ruleset at the bottom of any rulesets that are currently present on the page.
One or more conditions (IF statements) and one or more actions may be included in each ruleset (THEN).
Each ruleset invariably contains an ELSE option in order to account for all possible circumstances in which the condition or conditions are not satisfied. This configuration parameter may be found at the bottom of the “Actions” panel, and it only offers two choices: “Do the opposite,” or “Do nothing.”
Ordering rulesets
Rulebooks are utilised in the sequence in which they are presented on the page. You can rearrange the items by grabbing the hamburger icon in the top left corner and dragging and dropping them in a new order.
Be careful that the logic and actions of one rule set can supersede those of another rule set. For instance, if you use the Page URI condition in conjunction with the ELSE: Do the opposite action, this can very rapidly lead to results that are not what you planned.
Disabling rulesets
By default, new rulesets are enabled.
Uncheck the checkbox in the top left corner of the screen and click the “Save Changes” button if you want to (temporarily) disable a ruleset but maintain all of its settings.
To remove a ruleset from your account entirely, select the red “x” located in the upper right hand corner.
Naming rulesets
You can give each ruleset a name or a description to make it simpler to differentiate between them or to remember what their purpose was.
To modify the label, select “Change me” and then select “Save Changes” after you are through.
Conditions
Conditions are what dictate what should be tested for (IF). You are not limited to using just one condition; rather, you have the option of combining many conditions using AND or OR logic.
If a ruleset does not contain any conditions, then its actions will be carried out no matter what.
Every ruleset always has an ELSE setting, so that it can account for any and all circumstances in which the condition or conditions are not satisfied. This configuration parameter may be found at the bottom of the “Actions” panel, and it only offers two choices: “Do the opposite,” or “Do nothing.”
Adding conditions
To add a condition, click the “Add condition” button on the toolbar.
Let’s imagine you want something specific to take place on yoursite.com/demo/cars/ in the event that the “Make” facet contains the value bmw. The illustration on the right demonstrates the two requirements that must be met in order to achieve that goal.
Combining multiple conditions
Simply repeat the process of clicking the “Add condition” button to tie together numerous criteria using the AND logical operator.
Click the “OR” button that is located to the right of an existing condition if you would rather utilise the OR logical operator.
Changelog
1.4.1
- FixedSwitched to the `facetwp_assets` hook to prevent script timing issues
1.4
- NewAdded ability to enable / disable specific rulesets
- NewAdded `FWPCL.run()` JS method to manually trigger logic
- ImprovedRemoved front-end jQuery dependency
- ImprovedBetter admin styling (inputs expand based on available space)
- ImprovedPHP housekeeping
1.3.1
- FixedSwitched from `init` to `facetwp_init` hook to prevent timing-related PHP error on FacetWP 3.8+
1.3.0
- NewAdded
facetwp/ruleset/apply
JS hook to support custom actions - NewAdded
$ACTIVE
selector (similar to$EMPTY
, but targets in-use facets) - NewAdded i18n support (props G3ronim0)
- ImprovedRemoved the modal
- ImprovedRemoved the unnecessary “ON” condition (now uses
facetwp-loaded
) - ImprovedStyling tweaks
Reviews
There are no reviews yet.