{"id":14525,"date":"2023-09-26T15:04:16","date_gmt":"2023-09-26T15:04:16","guid":{"rendered":"http:\/\/a8759758b2.nxcli.io\/?post_type=docs&#038;p=14525"},"modified":"2026-09-02T22:19:50","modified_gmt":"2026-09-02T22:19:50","password":"","slug":"developpeurs","status":"publish","type":"docs","link":"https:\/\/couponaffiliates.com\/fr\/docs\/developers\/","title":{"rendered":"D\u00e9veloppeurs : Extraits de code et ressources"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The REST API is <code>wcusage\/v2<\/code>. Enable it under <strong>Coupon Affiliates &gt; Admin Tools &gt; API<\/strong>, then see <a href=\"https:\/\/couponaffiliates.com\/docs\/api-webhooks\/\">API &amp; Webhooks<\/a> for merchant setup (keys, scopes, webhooks) and the <a href=\"https:\/\/couponaffiliates.com\/api-docs\/\">API documentation<\/a> for authentication, routes, payloads and examples.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Below are PHP snippets and resources that customers have asked for. They are not a substitute for the REST API reference.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Database Tables<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The plugin does have its own database tables that you can get certain data from:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">wcusage_activity &#8211; Activity log.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">wcusage_campaigns &#8211; Referral URL campaigns.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">wcusage_clicks &#8211; Referral URL clicks log.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">wcusage_directlinks &#8211; Direct link tracking domains.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">wcusage_mlainvites &#8211; Multi-Level affiliates invites.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">wcusage_payouts &#8211; Commission Payouts<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">wcusage_register &#8211; Affiliate registration applications.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Affiliate Orders<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$orders = wcusage_wh_getOrderbyCouponCode( $coupon_code, $start_date, $end_date, &#039;&#039;, 1 );<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Order Data<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$order_data = wcusage_calculate_order_data( $order_id, $coupon_code, 0, 1 );<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To get the commission from the order for example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$commission = $order_data[&#039;totalcommission&#039;];<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Affiliate URL<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Get the affiliate URL for a coupon via the following function:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$coupon_code = &quot;&quot;; \/\/ Set the coupon code name here.\n$affiliate_url = wcusage_get_affiliate_url($coupon_code);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Or if you want to build your own custom URL here&#8217;s an example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$coupon_code = &quot;&quot;; \/\/ Set the coupon code name here.\n$prefix = wcusage_get_setting_value(&#039;wcusage_field_urls_prefix&#039;, &#039;coupon&#039;);\n$affiliate_url = get_home_url() . &quot;?&quot; . $prefix . &quot;=&quot; . $coupon_code;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Total Sales and Commission<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Get the total sales and commission earned by a certain coupon, without a certain date range. <em>Leave $start_date empty to get all sales.<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$orders = wcusage_wh_getOrderbyCouponCode( $coupon_code, $start_date, $end_date, &#039;&#039;, 1 );\n$total_orders = $orders[&#039;total_orders&#039;]; \/\/ Total Sales\n$total_discounts = $orders[&#039;full_discount&#039;]; \/\/ Total Discounts\n$total_commission = $orders[&#039;total_commission&#039;]; \/\/ Total Commission\n$order_count = $orders[&#039;total_count&#039;]; \/\/ Orders Count<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Unpaid Commission<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Get the total unpaid commission for an affiliate coupon.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$coupon_id = &quot;&quot;; \/\/ Set the coupon code ID here.\n$unpaid_commission = get_post_meta( $coupon_id, &#039;wcu_text_unpaid_commission&#039;, true );<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Hook (Action): New Affiliate Registration Submitted<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When there is a new affiliate registration, it will run the &#8220;wcusage_hook_registration_new&#8221; hook that will pass the registration ID, user ID, and coupon code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You could therefore call this hook to automatically accept the registration under certain conditions with the &#8220;wcusage_set_registration_status&#8221; function. For example this will automatically accept the registration if the users role is &#8220;example&#8221;:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>add_action( &#039;wcusage_hook_registration_new&#039;, &#039;trigger_wcusage_hook_registration_new&#039;, 10, 3 );\nfunction trigger_wcusage_hook_registration_new( $registration_id, $user_id, $coupon_code ) {\n    $user_info = get_userdata( $user_id );\n    $roles = $user_info-&gt;roles;\n\n    if ( in_array( &#039;example&#039;, $roles ) ) {\n        wcusage_set_registration_status( &#039;accepted&#039;, $registration_id, $user_id, $coupon_code, &#039;&#039;, &#039;&#039; );\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Hook (Action): New Affiliate Accepted<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When a new affiliate is accepted and added to your program, it will run the &#8220;wcusage_hook_affiliate_register_accepted&#8221; that will pass the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>$id &#8211; Registration ID.<\/li>\n\n\n\n<li>$userid &#8211; User ID.<\/li>\n\n\n\n<li>$coupon_code &#8211; Coupon Code.<\/li>\n\n\n\n<li>$message &#8211; The registration acceptance message.<\/li>\n\n\n\n<li>$status &#8211; The status of their registration.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>add_action( &#039;wcusage_hook_affiliate_register_accepted&#039;, &#039;trigger_wcusage_hook_registration_accepted&#039;, 10, 5 );\nfunction trigger_wcusage_hook_registration_accepted( $id, $userid, $coupon_code, $message, $status ) {\n\/\/ Your code here.\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Legacy v1 API<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The original three endpoints under <code>woo-coupon-usage\/v1<\/code> are still registered for existing integrations. They require a WordPress <strong>administrator<\/strong> role. They are not the current API. New integrations should use <code>wcusage\/v2<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>GET<\/strong> <code>\/wp-json\/woo-coupon-usage\/v1\/coupon-info<\/code> with <code>coupon_id<\/code>. Returns <code>coupon_name<\/code>, <code>unpaid_commission<\/code>, and <code>pending_payouts<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>GET<\/strong> <code>\/wp-json\/woo-coupon-usage\/v1\/users-coupons<\/code> with <code>user<\/code> (the login name). Returns coupon IDs assigned to that user, with unpaid commission.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>POST<\/strong> <code>\/wp-json\/woo-coupon-usage\/v1\/request-payout<\/code> with <code>coupon_id<\/code> and <code>user<\/code> (login). Returns <code>1<\/code> on success or <code>0<\/code> on failure. PRO.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Need help with a custom function? Feel free to contact us and we may be able to point you in the right direction.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The REST API is wcusage\/v2. Enable it under Coupon Affiliates &gt; Admin Tools &gt; API, then see API &amp; Webhooks for merchant setup (keys, scopes, webhooks) and the API documentation for authentication, routes, payloads and examples. Below are PHP snippets and resources that customers have asked for. They are not a substitute for the REST [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","footnotes":"","_links_to":"","_links_to_target":""},"doc_category":[136],"doc_tag":[],"class_list":["post-14525","docs","type-docs","status-publish","hentry","doc_category-developers","wpbf-post"],"year_month":"2026-09","word_count":697,"total_views":"3820","reactions":{"happy":"0","normal":"0","sad":"0"},"author_info":{"display_name":"Elliot Sowersby","author_link":"#"},"doc_category_info":[{"term_name":"Developers","term_url":"https:\/\/couponaffiliates.com\/fr\/docs-category\/developers\/"}],"doc_tag_info":[],"taxonomy_info":{"doc_category":[{"value":136,"label":"Developers"}]},"featured_image_src_large":false,"comment_info":0,"knowledge_base_info":[],"knowledge_base_slug":[],"_links":{"self":[{"href":"https:\/\/couponaffiliates.com\/fr\/wp-json\/wp\/v2\/docs\/14525","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/couponaffiliates.com\/fr\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/couponaffiliates.com\/fr\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/couponaffiliates.com\/fr\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/couponaffiliates.com\/fr\/wp-json\/wp\/v2\/comments?post=14525"}],"version-history":[{"count":25,"href":"https:\/\/couponaffiliates.com\/fr\/wp-json\/wp\/v2\/docs\/14525\/revisions"}],"predecessor-version":[{"id":24609,"href":"https:\/\/couponaffiliates.com\/fr\/wp-json\/wp\/v2\/docs\/14525\/revisions\/24609"}],"wp:attachment":[{"href":"https:\/\/couponaffiliates.com\/fr\/wp-json\/wp\/v2\/media?parent=14525"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/couponaffiliates.com\/fr\/wp-json\/wp\/v2\/doc_category?post=14525"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/couponaffiliates.com\/fr\/wp-json\/wp\/v2\/doc_tag?post=14525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}