Skip to main content
Cookbook Marketing AffiliateWP

Credit an Affiliate for a Missed Sale with AffiliateWP and AI

Check the order, rule out a double credit, work out the commission and add it as unpaid on your yes.

Difficulty Beginner
Time ~5 min

Prerequisites

A site connected to WPVibe running AffiliateWP 2.37 or newer (tested on 2.37.1) on WordPress 6.9 or newer, with an administrator account. WooCommerce for the order lookup. Changes need AffiliateWP's write access on: Affiliates > Tools > AI MCP > Enable MCP Write Access.

The prompt
My WordPress site runs AffiliateWP and WooCommerce. Credit [affiliate name or email] for WooCommerce order [order number], which AffiliateWP did not track. Reason: [for example: the customer bought from another device after clicking their link].

1. Run get_ability_info for each AffiliateWP ability this uses: affiliatewp/list-affiliates, affiliatewp/list-referrals, affiliatewp/get-affiliate, affiliatewp/get-program-settings and affiliatewp/add-referral. If one is not found, stop and tell me this needs AffiliateWP 2.37 or newer on WordPress 6.9 or newer. If affiliatewp/add-referral shows meta.mcp.public false, AffiliateWP is not letting AI make changes: tell me to switch on Enable MCP Write Access under Affiliates > Tools > AI MCP (I can switch it off again afterwards), and stop.
2. Read the order with rest_api GET /wc/v3/orders/ORDER_ID and fields id,number,status,total,total_tax,shipping_total,shipping_tax,currency,date_created,coupon_lines,line_items,fee_lines,refunds. Check the number it returns is the one I gave. If not (my store may use custom order numbers), stop and ask me for the order ID from the address of the order's edit screen. If its status is not completed or processing, stop and tell me.
3. Run affiliatewp/list-referrals with reference ORDER_ID (and again with the order's number if it is different). If any referral exists for this order, for any affiliate and in any status, show it and stop: don't credit a sale twice.
4. If I gave a name, find the affiliate with affiliatewp/list-affiliates search NAME, and ask me which one if more than one matches. Run affiliatewp/get-affiliate with their affiliate_id (or account email). If their status is not active, stop and tell me. Their rate and rate_type are what applies now, including any group rate. Run affiliatewp/get-program-settings for exclude_shipping, exclude_tax and currency.
5. Work out the commission the way AffiliateWP does for a tracked order. For a percentage rate: add up each line item's total (after discounts), plus its total_tax unless exclude_tax is true; unless exclude_shipping is true, add shipping_total, plus shipping_tax unless exclude_tax is true; never count fee_lines; if the order has refunds (each refund's total is negative and includes refunded tax and shipping), show me the commission with and without them and let me choose; multiply by the rate divided by 100 and round to cents. For a flat rate, show me the rate and ask me for the amount. If has_custom_rate is false, a product or category with its own AffiliateWP rate, or a product with referrals turned off, would have changed the tracked amount: tell me so I can check this order's products and correct the amount.
6. Show me the order (number, date, total, status), the affiliate, the rate, the commission and the description the affiliate will see. Tell me that adding it as unpaid makes AffiliateWP email the affiliate and the affiliate manager when those emails are on. Wait for my yes or a different amount.
7. On my yes, run affiliatewp/add-referral with affiliate_id, amount, description "WooCommerce order ORDER_NUMBER, credited by hand: [reason]", reference ORDER_ID, status unpaid and type sale.
8. Check it with affiliatewp/list-referrals reference ORDER_ID and tell me the referral id. To undo, run affiliatewp/set-referral-status with that referral_id and status rejected. If the order is refunded later, AffiliateWP won't reject this referral by itself; reject it the same way. Don't also assign this order to an affiliate in the AffiliateWP box on the order screen: that would credit it twice.
Already connected?

Skip pasting the full prompt. Drop this into your AI on a site that already has WPVibe:

Run the “Credit an Affiliate for a Missed Sale with AffiliateWP and AI” recipe from the WPVibe cookbook on my connected site.

An affiliate writes in: my reader bought last week and I got nothing. The cookie was cleared, the order came through a different browser, or the customer used a coupon that wasn’t tied to anyone. Working out the right commission means opening the order, finding the affiliate’s rate and checking the sale wasn’t already credited.

The AI reads the WooCommerce order, checks AffiliateWP has no referral for it already, works out the commission from the affiliate’s current rate and your program’s shipping and tax rules, and shows you the sum. It adds the referral as unpaid only on your yes, with the order number on it.

A referral added by hand isn’t linked to the order the way a tracked one is, so if that order is refunded later AffiliateWP won’t reject the commission on its own. Reject it then, or run the payday check, which looks for exactly that.

Outcome

An unpaid referral for the affiliate, with the order number on it, for the commission you approved.