Targeting Applied Discount Codes
AdsGun provides a powerful way to style elements based on applied discount codes using CSS attribute selectors. This allows you to dynamically change the appearance of your site when specific codes are active.
This selector targets elements when the discount code "DISCODE" is applied.
Key Points:
The ~=
operator matches elements with an attribute value containing a given word, delimited by spaces.
To target multiple codes, you need to chain the selectors.
The order of the chained selectors doesn't matter, as it will match regardless of the order the codes were applied.
Examples:
Targeting a single code or multiple codes:
Adding a site-wide banner for a major sale:
This corrected version applies the ::before pseudo-element directly to the element with the data-adsguncode attribute (which is the body tag in this case), ensuring that the banner is correctly displayed when the "BIGANNUAL" code is active.
Remember:The data-adsguncode attribute is added to the body tag.
When using pseudo-elements like ::before or ::after, apply them directly to the selector with the data-adsguncode attribute.
Adjust other styles (like padding-top) on the same selector to accommodate the added elements.
This event fires when the AdsGun library is loaded and the AdsGun object is attached to the window, but before initialization begins.
This event is dispatched after the initialization completes. The initialization checks for applicable discount codes, applies them, and displays savings.
The deactivate
function is an asynchronous method that deactivates all applied codes.
By default, it reloads the page after deactivation, but this behavior can be prevented.
ParameterspreventReload
(boolean, optional): If set to true
, prevents the page from reloading after deactivation. Default is false
.
Returns
A Promise that resolves when the deactivation process is complete.
Examples
Using async/await:
Using .then():