How can we help?

Search the documentation or ask the AI agent anything about the plugin.

Entwickler: Code-Schnipsel und Ressourcen

Updated September 5, 2026

The REST API is wcusage/v2. Enable it under Coupon Affiliates > Admin Tools > API, then see API & 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 API reference.

Datenbank-Tabellen

Das Plugin hat seine eigenen Datenbanktabellen, aus denen Sie bestimmte Daten abrufen können:

wcusage_activity - Aktivitätsprotokoll.

wcusage_api_keys – REST API keys (hashed), with their scopes, status and last-used date.

wcusage_campaigns - Empfehlungs-URL-Kampagnen.

wcusage_clicks - Protokoll der Klicks auf Verweis-URLs.

wcusage_directlinks - Domains mit direkter Linkverfolgung.

wcusage_mlainvites - Einladungen für Multi-Level-Partner.

wcusage_payouts - Provisionsausschüttungen

wcusage_register - Anwendungen zur Registrierung von Partnern.

wcusage_rewards_log – Log of performance bonuses (rewards) earned by affiliates, including the reward name, requirement met and bonuses granted.

Webhooks are not stored in a table; they are saved in the wcusage_api_webhooks option.

Affiliate-Bestellungen

Ermittelt alle Partnerbestellungen für einen Coupon, ohne bestimmten Datenbereich. Dies gibt ein Array von Daten zurück, das die Gesamtberechnungen für alle Bestellungen und alle einzelnen Bestellungen enthält.

$orders = wcusage_wh_getOrderbyCouponCode( $coupon_code, $start_date, $end_date, '', 1 );

Daten bestellen

Mit dieser Funktion können Sie ein Array von Partnerdaten für eine bestimmte Bestellung abrufen. Diese Funktion gibt ein Array von Daten einschließlich der Provisionseinnahmen zurück.

$order_data = wcusage_calculate_order_data( $order_id, $coupon_code, 0, 1 );

Zum Beispiel, um die Provision für die Bestellung zu erhalten:

$commission = $order_data['totalcommission'];

Partner-URL

Holen Sie sich die Partner-URL für einen Coupon mit der folgenden Funktion:

$coupon_code = ""; // Set the coupon code name here.
$affiliate_url = wcusage_get_affiliate_url($coupon_code);

Wenn Sie Ihre eigene benutzerdefinierte URL erstellen möchten, finden Sie hier ein Beispiel:

$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;

Gesamtumsatz und Provision

Ermitteln Sie den Gesamtumsatz und die Provisionen, die mit einem bestimmten Coupon erzielt wurden, ohne einen bestimmten Datumsbereich. 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

Unbezahlte Kommission

Ermitteln Sie die gesamte unbezahlte Provision für einen Affiliate-Gutschein.

$coupon_id = ""; // Set the coupon code ID here.
$unpaid_commission = get_post_meta( $coupon_id, 'wcu_text_unpaid_commission', true );

Haken (Aktion): Registrierung eines neuen Partners eingereicht

Bei einer neuen Partnerregistrierung wird der Hook "wcusage_hook_registration_new" ausgeführt, der die Registrierungs-ID, die Benutzer-ID und den Gutscheincode übergibt.

Sie können daher diesen Hook aufrufen, um die Registrierung unter bestimmten Bedingungen mit der Funktion "wcusage_set_registration_status" automatisch zu akzeptieren. Zum Beispiel wird die Registrierung automatisch akzeptiert, wenn der Benutzer die Rolle "Beispiel" hat:

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, '', '' );
    }
}

Haken (Aktion): Neue Mitgliedsorganisation Akzeptiert

Wenn ein neuer Partner akzeptiert und zu Ihrem Programm hinzugefügt wird, wird die Funktion "wcusage_hook_affiliate_register_accepted" ausgeführt, die Folgendes übermittelt:

  • $id - Registrierungs-ID.
  • $userid - Benutzer-ID.
  • $coupon_code - Gutscheincode.
  • $message - Die Nachricht über die Annahme der Registrierung.
  • $status - Der Status der Registrierung.
add_action( 'wcusage_hook_affiliate_register_accepted', 'trigger_wcusage_hook_registration_accepted', 10, 5 );
function trigger_wcusage_hook_registration_accepted( $id, $userid, $coupon_code, $message, $status ) {
// Your code here.
}

Hook (Action): Trigger a Performance Bonus from a Custom Event (PRO)

Performance Bonuses can be triggered from your own theme or plugin code. When creating a bonus, set the trigger type to “Developers: Custom Event / Action” and enter a Custom Event Key. Then fire the “wcusage_custom_event” action with that same key whenever the event happens:

do_action( 'wcusage_custom_event', 'your_event_key', $user_id );
// Or target a specific affiliate coupon:
do_action( 'wcusage_custom_event', 'your_event_key', $user_id, array(), 'COUPONCODE' );
  • ‘your_event_key’ must match the Custom Event Key entered on the bonus.
  • $user_id is the WordPress user ID of the affiliate to reward.
  • The fourth parameter (optional) is a coupon code or coupon post ID to target a specific affiliate coupon. When omitted, all coupons belonging to the user are checked.

See (PRO) Leistungsprämien for how to set up the bonus itself.

Legacy v1 API

The original three endpoints under woo-coupon-usage/v1 are still registered for existing integrations. They require a WordPress administrator role. They are not the current API. New integrations should use wcusage/v2.

GET /wp-json/woo-coupon-usage/v1/coupon-info with coupon_id. Returns gutschein_name, unbezahlte_Kommissionund ausstehende_Auszahlungen.

GET /wp-json/woo-coupon-usage/v1/benutzer-coupons with Benutzer (the login name). Returns coupon IDs assigned to that user, with unpaid commission.

POST /wp-json/woo-coupon-usage/v1/anforderung-auszahlung with coupon_id und Benutzer (login). Returns 1 on success or 0 on failure. PRO.

Benötigen Sie Hilfe bei einer benutzerdefinierten Funktion? Wenden Sie sich an uns, vielleicht können wir Ihnen den richtigen Weg weisen.

Was this article helpful?