Gatemi Product Badges Developer Reference

The free edition applies no filters or actions of its own. Everything under Filters and Actions is the full edition's.

Filters — Full edition

gmbg_product_badges

The badges one product wears, after they are matched and scheduled, before they are printed.

Argument Type
$badges array The matched badges, in your order
$product WC_Product The product

Return an array of badges. Each badge needs the keys printed: text, position, shape, background, color.

// A "Bestseller" badge on products with more than 100 sales.
add_filter( 'gmbg_product_badges', function ( $badges, $product ) {
	if ( (int) $product->get_total_sales() > 100 ) {
		$badges[] = array(
			'id'         => 'bestseller',
			'text'       => 'Bestseller',
			'position'   => 'top-right',
			'shape'      => 'rounded',
			'background' => '#b45309',
			'color'      => '#ffffff',
		);
	}
	return $badges;
}, 10, 2 );

gmbg_badges

The whole badge list as read from the option, before matching. Non-array entries are dropped.

gmbg_settings

The merged placement settings. Must return an array.

gmbg_modules, gmbg_license_api_url, gmbg_update_cache_ttl

The module list, the gatemi.com licensing endpoint and the update payload's cache time in seconds.

Actions — Full edition

gmbg_booted

Fires once the plugin's modules have booted, with the service container.

Storage

gmbg_badges (both editions)

A list of badges:

array(
	'id'         => 'sale',
	'text'       => 'Sale',
	'enabled'    => 'yes',
	'condition'  => 'sale',        // sale | out_of_stock | manual | new | low_stock | featured
	'position'   => 'top-left',    // top-left | top-right | bottom-left | bottom-right
	'shape'      => 'rectangle',   // rectangle | rounded | circle
	'background' => '#1e1e1e',
	'color'      => '#ffffff',
	'days'       => 30,
	'products'   => array(),
	'categories' => array(),
	'starts'     => '',            // YYYY-MM-DD
	'ends'       => '',
);

The free edition edits text, condition, products and categories of the first three, and carries every other key through a save unchanged.

gmbg_settings (full edition)

on_archives (yes), on_single (yes), hide_wc_onsale (no).

Also gmbg_license, the transient gmbg_update_payload and the cron event gmbg_license_check. No tables. One product meta key: _gmbg_published, the store-clock timestamp written on a product's first transition_post_status to publish and read by the new condition; removed at uninstall.

Where badges are printed

Hook Priority
woocommerce_before_shop_loop_item_title 15 Listings
woocommerce_before_single_product_summary 15 Product page

With Remove WooCommerce's own sale flash, the full edition removes woocommerce_show_product_loop_sale_flash and woocommerce_show_product_sale_flash (both at priority 10).

A product card or page that does not fire these hooks shows no badges.

CSS

The stylesheet badges.css is enqueued in the head on WooCommerce pages (is_woocommerce()) and, anywhere else, when a badge is rendered (it then prints in the footer). Both editions position li.wc-block-product beside the classic product wrappers.

Full edition

Class Element
gmbg-badges One corner's stack
gmbg-at-top-left, gmbg-at-top-right, gmbg-at-bottom-left, gmbg-at-bottom-right The corner
gmbg-badge One badge
gmbg-shape-rectangle, gmbg-shape-rounded, gmbg-shape-circle The shape

Colours are the custom properties --gmbg-bg and --gmbg-fg on each .gmbg-badge.

.gmbg-badge { font-size: 12px; letter-spacing: .04em; text-transform: uppercase; }

Free edition

Class Element
gmbgf-badges gmbgf-at-top-left The stack
gmbgf-badge One badge (no inline style)
.gmbgf-badge { background: #b91c1c; color: #fff; }
Shopping Cart
Scroll to Top