This developer reference for Sitewide Discount for WooCommerce lists the helper functions, filter, action and shortcode you can use in themes and custom code, plus the WooCommerce price hooks the plugin uses. Settings live at WPFactory > Global Shop Discount. Everything here is in both the free and Pro versions.
Helper functions #
| Function | Returns |
|---|---|
alg_wc_gsd_is_discount_product( $product ) |
true if a discount group changes this product’s price, otherwise false. |
alg_wc_gsd_get_product_discount_groups( $product ) |
An array of the group numbers that apply to the product. With Stop on first matching discount group on, this holds at most one group. |
alg_wc_gsd_get_product_ids( $product_query_args = array( 'limit' => -1 ), $incl_on_sale = true, $use_transient = false ) |
An array of product IDs that are discounted by the plugin. $product_query_args is passed to wc_get_products(). With $incl_on_sale true, products already on sale are included too. With $use_transient true, results are cached for 24 hours. |
Each function takes a WC_Product object where a product is expected, and returns false if the plugin is not loaded. The discount engine only loads on the storefront unless Apply discounts in backend is enabled, so call these functions from front-end code.
Example: add a badge to discounted products #
add_action( 'woocommerce_before_shop_loop_item_title', function () {
global $product;
if ( function_exists( 'alg_wc_gsd_is_discount_product' ) && alg_wc_gsd_is_discount_product( $product ) ) {
echo '<span class="my-sitewide-badge">Sitewide sale</span>';
}
} );
Shortcode #
[alg_wc_gsd_products] outputs a WooCommerce [products] grid of all products currently on sale.
| Attribute | Description | Default |
|---|---|---|
use_transient |
Cache the on-sale product IDs in the alg_wc_gsd_products_onsale transient for 24 hours. |
Off |
on_empty |
Output when no products are found. | Empty |
| Other attributes | Passed through to [products], with ids set to the found products. |
None |
Filter #
| Filter | Parameters | Use |
|---|---|---|
alg_wc_global_shop_discount_shortcode_product_ids |
$product_ids_on_sale (array), $atts (shortcode attributes) |
Change the product IDs the [alg_wc_gsd_products] shortcode displays. Runs before the result is cached. |
add_filter( 'alg_wc_global_shop_discount_shortcode_product_ids', function ( $ids, $atts ) {
return array_diff( $ids, array( 123 ) ); // Hide product 123.
}, 10, 2 );
Action #
| Action | When it fires |
|---|---|
alg_wc_global_shop_discount_settings_saved |
After the plugin settings are saved (the Tools run on this action). |
WooCommerce hooks the plugin filters #
Prices are changed at priority PHP_INT_MAX on these filters, so the discount is applied after most other pricing code:
woocommerce_product_get_price,woocommerce_product_get_sale_price,woocommerce_product_get_regular_price(the regular price is passed through unchanged)woocommerce_product_variation_get_price,woocommerce_product_variation_get_sale_price,woocommerce_product_variation_get_regular_pricewoocommerce_variation_prices_price,woocommerce_variation_prices_sale_price,woocommerce_variation_prices_regular_pricewoocommerce_get_variation_prices_hash(adds the group settings to the variation price cache key)woocommerce_get_price_including_tax,woocommerce_get_price_excluding_tax(grouped products)
If your code needs the undiscounted price, read the stored meta (for example _price) or use $product->get_price( 'edit' ), which bypasses these filters.
Stored data #
- Settings are stored as WordPress options prefixed
alg_wc_global_shop_discount_. Group options are arrays keyed by group number. See the settings reference for every option ID. - Transients:
alg_wc_gsd_products_onsale(shortcode) andalg_wc_gsd_products_{md5}(fromalg_wc_gsd_get_product_ids()with caching on). - The plugin does not write product prices unless you run Tools > Save prices in DB for all products.
Need a hand? Our team answers every ticket on the Sitewide Discount support forum.