WooCommerce Integration Guide

Learn how to integrate DaisyChain with your WooCommerce store.

Overview

Integration Features

Referral Tracking

Track referrals and conversions

Revenue Attribution

Monitor referral revenue and ROI

Setup

1. Configure Webhooks

  1. Go to Settings → Webhooks
  2. Add a new webhook endpoint
  3. Enable these notifications:
    • new_order
    • order_status_changed
    • order_payment_status_changed
    • refund_created

2. Install Dependencies

npm install @daisychain/sdk

3. Initialize Client

const { DaisyChain } = require('@daisychain/sdk');

const client = new DaisyChain({
  apiKey: process.env.DAISYCHAIN_API_KEY,
  testMode: true // Enable test mode for development
});

Checkout Integration

1. Add Referral Field

add_action('woocommerce_before_checkout_form', 'add_referral_field');

function add_referral_field() {
  woocommerce_form_field('referral_code', array(
    'type' => 'text',
    'class' => array('form-row-wide'),
    'label' => __('Referral Code'),
    'placeholder' => __('Enter referral code'),
    'required' => false,
  ));
}

2. Handle Orders

add_action('woocommerce_checkout_order_processed', 'handle_referral_order');

function handle_referral_order($order_id) {
  $order = wc_get_order($order_id);
  $referral_code = $_POST['referral_code'];
  
  if ($referral_code) {
    $api_key = get_option('daisychain_api_key');
    $url = 'https://api.daisychain.la/api/referrals';
    
    $response = wp_remote_post($url, array(
      'headers' => array(
        'Content-Type' => 'application/json',
        'X-API-Key' => $api_key
      ),
      'body' => json_encode(array(
        'referrerIdentifier' => $referral_code,
        'customerId' => $order->get_customer_id(),
        'orderId' => $order->get_id(),
        'orderAmount' => $order->get_total()
      ))
    ));
    
    if (is_wp_error($response)) {
      error_log('DaisyChain API Error: ' . $response->get_error_message());
    }
  }
}

Testing Checklist

  1. Create test products
  2. Place test orders with referral codes
  3. Verify order tracking
  4. Check referral status in dashboard
  5. Test refund handling

Best Practices

Security

  • • Sanitize all inputs
  • • Use nonces for forms
  • • Validate capabilities

Performance

  • • Cache API responses
  • • Use WordPress transients
  • • Optimize database queries

Troubleshooting

Common Issues

API Connection Issues

  • • Check API credentials
  • • Verify SSL certificate
  • • Check server requirements

Plugin Conflicts

  • • Test in default theme
  • • Disable other plugins
  • • Check error logs

Support

Need help with your WooCommerce integration?