We do not currently have in-depth developer documentation available, but here are some useful code snippets and resources for developers.
Database Tables
The plugin does have its own database tables that you can get certain data from:
wcusage_activity – Activity log.
wcusage_campaigns – Referral URL campaigns.
wcusage_clicks – Referral URL clicks log.
wcusage_directlinks – Direct link tracking domains.
wcusage_mlainvites – Multi-Level affiliates invites.
wcusage_payouts – Commission Payouts
wcusage_register – Affiliate registration applications.
Affiliate Orders
Get all affiliate orders for a coupon, without certain data range. This returns an array of data including the total calculations for all the orders, and all the individual orders.
$orders = wcusage_wh_getOrderbyCouponCode( $coupon_code, $start_date, $end_date, '', 1 );
Order Data
You can get an array of affiliate related data for a certain order via this function. This returns an array of data including the commission earnings.
$order_data = wcusage_calculate_order_data( $order_id, $coupon_code, 0, 1 );
To get the commission from the order for example:
$commission = $order_data['totalcommission'];
Affiliate URL
Get the affiliate URL for a coupon via the following function:
$coupon_code = ""; // Set the coupon code name here.
$affiliate_url = wcusage_get_affiliate_url($coupon_code);
Or if you want to build your own custom URL here’s an example:
$coupon_code = ""; // Set the coupon code name here.
$prefix = wcusage_get_setting_value('wcusage_field_urls_prefix', 'coupon');
$affiliate_url = get_home_url() . "?" . $prefix . "=" . $coupon_code;
Total Sales and Commission
Get the total sales and commission earned by a certain coupon, without a certain date range. Leave $start_date empty to get all sales.
$orders = wcusage_wh_getOrderbyCouponCode( $coupon_code, $start_date, $end_date, '', 1 );
$total_orders = $orders['total_orders']; // Total Sales
$total_discounts = $orders['full_discount']; // Total Discounts
$total_commission = $orders['total_commission']; // Total Commission
$order_count = $orders['total_count']; // Orders Count
Unpaid Commission
Get the total unpaid commission for an affiliate coupon.
$coupon_id = ""; // Set the coupon code ID here.
$unpaid_commission = get_post_meta( $coupon_id, 'wcu_text_unpaid_commission', true );
Hook (Action): New Affiliate Registration
When there is a new affiliate registration, it will run the “wcusage_hook_registration_new” hook that will pass the registration ID, user ID, and coupon code.
You could therefore call this hook to automatically accept the registration under certain conditions with the “wcusage_set_registration_status” function. For example this will automatically accept the registration if the users role is “example”:
add_action( 'wcusage_hook_registration_new', 'trigger_wcusage_hook_registration_new', 10, 3 );
function trigger_wcusage_hook_registration_new( $registration_id, $user_id, $coupon_code ) {
$user_info = get_userdata( $user_id );
$roles = $user_info->roles;
if ( in_array( 'example', $roles ) ) {
wcusage_set_registration_status( 'accepted', $registration_id, $user_id, $coupon_code, '', '' );
}
}
API Endpoint: Coupon Info
The Coupon Info
API endpoint allows you to retrieve details about a specific coupon by its ID. This includes the coupon’s name, unpaid commission, and pending payouts, making it an essential tool for tracking coupon performance and payout status. Only administrators can access this endpoint.
To use the API, send a GET request to /wp-json/woo-coupon-usage/v1/coupon-info
with the required parameter coupon_id
(the ID of the coupon you want to query). The response will include an array containing the coupon_name
, unpaid_commission
, and pending_payouts
.
API Endpoint: Users Coupons
The User's Coupons
API endpoint allows you to retrieve a list of coupon IDs assigned to a specific user, along with their associated unpaid commission. This functionality is useful for monitoring and managing user-specific coupon assignments and commissions. Access to this endpoint is limited to administrators.
To use the API, send a GET request to /wp-json/woo-coupon-usage/v1/users-coupons
with the required parameter user
(the login name of the user whose coupons you want to retrieve). The API will return an array of coupon IDs along with their unpaid commission, providing an overview of the user’s coupon activity.
API Endpoint: Request Payout
The Request Payout
API endpoint allows you to trigger payout requests for a specific coupon. It verifies the user requesting the payout and checks if the coupon’s unpaid commission is valid and ready for processing.
To use the API, make a POST request to /wp-json/woo-coupon-usage/v1/request-payout
with two required parameters: coupon_id
(the ID of the coupon) and user
(the login name of the user requesting the payout). Ensure that the calling user has administrator permissions. Upon successful validation, the system processes the payout request and returns 1
for success or 0
for failure.
—
Need help with a custom function? Feel free to contact us and we may be able to point you in the right direction.