Hooks
Actions you can fire#
smartcouponx_trigger_coupon – ask the plugin to create a reward coupon from your own code. The plugin listens on this action and routes it to the right coupon builder.
do_action( 'smartcouponx_trigger_coupon', $trigger_type, $data );
$trigger_type | Required keys in $data |
|---|---|
post_purchase | order (a WC_Order) |
review | comment (a WP_Comment of type review) |
registration | user_id |
birthday | user_id |
newsletter | email |
referral | referrer_id, referee_id, optional order_id |
cart_value | trigger (rule array), user_id, optional cart_total |
cart_item | trigger (rule array), user_id, optional cart_items |
Example: send a birthday coupon to user 42 from a custom form:
do_action( 'smartcouponx_trigger_coupon', 'birthday', [ 'user_id' => 42 ] );
The abuse prevention limits and feature switches apply as usual, and the customer is emailed when the coupon is created.
smartcouponx_daily_maintenance – the WP-Cron event that sends birthday coupons and deletes old analytics rows. Run it on demand with WP-CLI:
wp cron event run smartcouponx_daily_maintenance
Filters#
| Filter | Default | Purpose |
|---|---|---|
smartcouponx_storeengine_store_url | https://technoleet.dev | License server URL (also the SMARTCOUPONX_STOREENGINE_STORE_URL constant) |
smartcouponx_storeengine_product_id | 23604 | StoreEngine product ID (also the SMARTCOUPONX_STOREENGINE_PRODUCT_ID constant) |
smartcouponx_storeengine_purchase_url | https://technoleet.dev/product/smartcouponx/ | “Purchase” link on the license screen |
smartcouponx_store_dashboard_url | https://technoleet.dev/dashboard/license-keys/ | “Manage License” link on the license screen |
PHP API#
$plugin = smartcouponx(); // main instance
$plugin->is_feature_enabled( 'review' ); // master switch AND the trigger switch
$plugin->get_option( 'post_purchase_amount' ); // any setting without the smartcouponx_ prefix
$coupons = $plugin->get_service( 'coupon_manager' );
$coupons->get_user_coupons( $user_id, 20 ); // WC_Coupon[] issued to a customer
$coupons->is_coupon_available( $coupon ); // not expired and not used up
$coupons->passes_abuse_checks( $user_id, false, 'review' );
$coupon_id = $coupons->create_coupon( [
'post_title' => '', // empty = generated SCX_ code
'post_content' => 'Manual reward',
'meta_input' => [
'discount_type' => 'fixed_cart',
'coupon_amount' => 5,
'customer_email' => 'customer@example.com',
'expiry_date' => '2026-12-31',
'smartcouponx_trigger_type' => 'manual',
'smartcouponx_user_id' => 42,
],
] );
Coupon meta written by the plugin: smartcouponx_trigger_type, smartcouponx_user_id, smartcouponx_order_id, smartcouponx_product_id, smartcouponx_referrer_id, smartcouponx_referee_id, smartcouponx_trigger_id, smartcouponx_cart_total, smartcouponx_cart_items. Order meta: _smartcouponx_post_purchase_coupon, _smartcouponx_referral_code, _smartcouponx_referral_processed, _smartcouponx_usage_tracked. Review meta: _smartcouponx_review_coupon. User meta: smartcouponx_referral_code, smartcouponx_received_triggers, smartcouponx_last_coupon_time, smartcouponx_birthday_coupon_year, and the birthday field the birthday trigger reads.
WooCommerce and WordPress hooks the plugin listens to#
| Hook | Used for |
|---|---|
woocommerce_order_status_processing, woocommerce_order_status_completed | Post-purchase coupons, referral rewards, redemption tracking |
woocommerce_order_status_cancelled, woocommerce_order_status_refunded | Trashing unused rewards, cancelling referrals |
comment_post, transition_comment_status | Review coupons |
user_register | Registration coupons |
woocommerce_cart_updated | Cart value and cart item rules |
woocommerce_checkout_order_processed, woocommerce_store_api_checkout_order_processed | Saving the referral code on the order (classic and block checkout) |
woocommerce_applied_coupon, woocommerce_removed_coupon | Analytics events |
woocommerce_account_dashboard, woocommerce_before_checkout_form | Coupon lists on My Account and classic checkout |
woocommerce_account_menu_items, woocommerce_account_referrals_endpoint | The Referrals page |
wp_privacy_personal_data_exporters, wp_privacy_personal_data_erasers | GDPR tools |
Front-end AJAX actions (logged-in customers, nonce smartcouponx_nonce)#
| Action | Purpose |
|---|---|
smartcouponx_apply_coupon | Apply a coupon code to the current cart (coupon_code) |
smartcouponx_get_user_coupons | List the current customer’s usable coupons |
smartcouponx_generate_referral_link | Return the customer’s referral code and link |
smartcouponx_get_referral_stats | Return the customer’s referral statistics |
smartcouponx_get_leaderboard | Top referrers with anonymised names |
