Gatemi Next Order Coupons Developer Reference

Hooks

The free edition applies no filters of its own: its behaviour is entirely what its settings screen shows. Every filter below belongs to the full edition.

Filter Arguments Use
gmnc_settings array $settings The merged settings, after defaults, every time they are read.
gmnc_coupon_kind string $kind, WC_Order $order What the order earns: first, next or none. Applied after the plugin's own rules.
gmnc_coupon WC_Coupon $coupon, WC_Order $order, string $kind The coupon just before it is saved. Return anything that is not a WC_Coupon to cancel the mint.
gmnc_email array $email, WC_Order $order, string $code The message, as to, subject, body. Return an empty array to send nothing.
gmnc_modules array $modules The ordered module list the plugin boots.
gmnc_license_api_url string $url The gatemi.com licensing endpoint.
gmnc_update_cache_ttl int $seconds How long the update information is cached (minimum 60).
gmnc_update_retry_ttl int $seconds How long to wait after a failed update check (minimum 60).
Action Arguments When
gmnc_booted Container $container After every module has booted.

The work itself runs on WooCommerce's woocommerce_order_status_completed (or woocommerce_order_status_processing when the full edition is set to Processing), at priority 10.

Returning values from gmnc_coupon_kind

first and next decide which email wording and coupon description are used; none means the order earns nothing and nothing is claimed. The filter runs after the enabled switch, the email check and the minimum, so it cannot bring back an order the plugin has already ruled out.

Examples

Only reward orders that did not use a coupon:

add_filter( 'gmnc_coupon_kind', function ( $kind, $order ) {
	if ( $order->get_coupon_codes() ) {
		return 'none';
	}
	return $kind;
}, 10, 2 );

Restrict every coupon to one product category:

add_filter( 'gmnc_coupon', function ( $coupon, $order, $kind ) {
	$coupon->set_product_categories( array( 42 ) );
	return $coupon;
}, 10, 3 );

Send the code through your own email system and skip the plugin's:

add_filter( 'gmnc_email', function ( $email, $order, $code ) {
	my_crm_send_coupon( $order->get_billing_email(), $code );
	return array(); // The coupon stays minted.
}, 10, 3 );

Cancelling the email never mints a second coupon later — the order is already claimed.

Data

Name Type Contents
gmnc_settings Option All settings, shared by both editions. Keys: enabled, status, first_order, next_order, discount_type, amount, prefix, expiry_days, min_spend, coupon_min_spend, first_subject, first_body, next_subject, next_body.
gmnc_license Option Full edition licence state.
gmnc_update_payload Transient Full edition cached update information.
gmnc_license_check Cron hook Full edition twice-daily licence check, only while a key is entered.
_gmnc_coupon Order meta The claim: pending while minting, then the code.

The plugin creates no tables, no post types and no product or user meta. The coupons are ordinary shop_coupon posts with WooCommerce's own fields: discount_type, coupon_amount, customer_email, usage_limit, usage_limit_per_user, individual_use, date_expires and, in the full edition, minimum_amount.

To find the order that earned a coupon, read the coupon's description ("… earned by order 1042.") or look the code up in _gmnc_coupon:

$orders = wc_get_orders( array(
	'meta_key'   => '_gmnc_coupon',
	'meta_value' => 'THANKS-7KQ2M9XA',
	'limit'      => 1,
) );

Constants

The full edition defines GMNC_VERSION, GMNC_PLUGIN_FILE, GMNC_PLUGIN_DIR, GMNC_PLUGIN_URL and GMNC_BASENAME. The free edition checks for GMNC_VERSION and stands down when it is defined.

Shopping Cart
Scroll to Top