How to Send New Order Data to QuickBooks Using WooCommerce Webhooks

Integrating WooCommerce with QuickBooks can significantly streamline your e-commerce operations, especially when it comes to managing orders and financial data. WooCommerce’s built-in webhook system offers a powerful way to automate this integration by sending new order data directly to QuickBooks. In this post, we’ll guide you through setting up a WooCommerce webhook to send order data to QuickBooks.


What Are WooCommerce Webhooks?

Webhooks are automated messages sent from one system to another in real-time. In the case of WooCommerce, a webhook can be triggered when specific events (like new orders) occur, pushing relevant data to an external system—in this case, QuickBooks.


Prerequisites

Before we dive in, make sure you have:

  1. WooCommerce Installed: Your WooCommerce store should be live and functional.
  2. QuickBooks Online Account: Ensure you have a QuickBooks account with API access enabled.
  3. A QuickBooks Integration App or Middleware: You’ll need middleware like Zapier, Integromat, or a custom script to handle the data transfer from WooCommerce to QuickBooks.
  4. Admin Access: Access to your WordPress admin dashboard and QuickBooks account.

Step 1: Set Up a Webhook in WooCommerce

  1. Log in to your WordPress admin dashboard.
  2. Go to WooCommerce > Settings > Advanced > Webhooks.
  3. Click the Add Webhook button.
  4. Configure the webhook:
    • Name: Enter a descriptive name (e.g., “New Order to QuickBooks”).
    • Status: Set to Active.
    • Topic: Select Order Created.
    • Delivery URL: Enter the URL of the middleware or script that will handle the data transfer to QuickBooks.
    • Secret: (Optional) Use this for securing your webhook with a secret key.
  5. Click Save Webhook.

Step 2: Retrieve QuickBooks API Credentials

  1. Log in to your QuickBooks Online Developer Account.
  2. Navigate to Apps > My Apps > Create New App.
  3. Select QuickBooks Online and Payments API.
  4. Obtain your Client ID and Client Secret. You’ll need these to authenticate API requests.

Step 3: Build or Configure Middleware

Middleware acts as a bridge between WooCommerce and QuickBooks, handling data formatting and API communication.

Option 1: Use a Pre-Built Integration (e.g., Zapier)

  1. Log in to Zapier and create a new Zap.
  2. Set WooCommerce as the trigger app and select the Order Created event.
  3. Authenticate your WooCommerce account.
  4. Add an action step and select QuickBooks Online.
  5. Choose the action (e.g., “Create Sales Receipt” or “Create Invoice”).
  6. Map WooCommerce order fields (e.g., customer name, order total) to QuickBooks fields.

Option 2: Create a Custom Script

If you’re coding your own integration:

  1. Write a script to receive the webhook data at your specified Delivery URL.
  2. Use the WooCommerce API response to extract order details like customer information, products, and totals.
  3. Authenticate with the QuickBooks API using OAuth2 and your API credentials.
  4. Format the data to match QuickBooks API requirements and send a POST request to create the order in QuickBooks.

Here’s a sample PHP snippet to handle WooCommerce webhook data:

<?php
// QuickBooks API credentials
$client_id = 'YOUR_CLIENT_ID';
$client_secret = 'YOUR_CLIENT_SECRET';
$redirect_uri = 'YOUR_REDIRECT_URI';
$auth_url = 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer';

// Function to handle incoming webhook data
function handle_webhook($webhook_data) {
    $order_id = $webhook_data['id'];
    $order_total = $webhook_data['total'];
    $customer_email = $webhook_data['billing']['email'];

    // Prepare QuickBooks API request
    $quickbooks_data = [
        'CustomerRef' => $customer_email,
        'TotalAmt' => $order_total,
        'Line' => $webhook_data['line_items']
    ];

    // Send data to QuickBooks
    $response = send_to_quickbooks($quickbooks_data);
    return $response;
}

// Function to send data to QuickBooks
function send_to_quickbooks($data) {
    global $auth_url, $client_id, $client_secret;

    $headers = [
        'Authorization: Bearer YOUR_ACCESS_TOKEN',
        'Content-Type: application/json'
    ];

    $ch = curl_init($auth_url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $response = curl_exec($ch);
    curl_close($ch);

    return $response;
}
?>

Step 4: Test the Integration

  1. Place a test order in your WooCommerce store.
  2. Verify that the webhook triggers and sends the order data to your middleware or script.
  3. Check your QuickBooks account to confirm the order data is correctly recorded.

Step 5: Monitor and Maintain

  • Regularly monitor webhook logs in WooCommerce to ensure data is being sent without issues.
  • Periodically update your middleware or script to accommodate changes in WooCommerce or QuickBooks APIs.

Conclusion

By using WooCommerce webhooks, you can automate the transfer of order data to QuickBooks, saving time and reducing manual errors. Whether you use a no-code tool like Zapier or create your own integration, this setup ensures seamless synchronization between your e-commerce store and accounting software.

If you have questions or run into issues, feel free to drop them in the comments!

Photo by Neil Kami on Unsplash

Get A No Obligation Quote

Do You Need Help With Your WooCommerce Site?

Click through to the next page and complete the form to get a free no obligation quote to fix any issue you are having with your WooCommerce site.