WooCommerce Integration
Connect your WooCommerce store to Dark Obsidian using our PHP SDK. Orders sync automatically, inventory updates in real time, and customers land in your CRM.
How It Works
WooCommerce triggers a webhook when an order is placed or paid. Your WordPress site calls Dark Obsidian's POST /orders endpoint. One call handles everything:
- Sale created in Dark Obsidian with all line items
- Inventory deducted from your warehouse
- Customer found or created in CRM
- Loyalty points awarded automatically
- Financial reports updated
Prerequisites
- WordPress with WooCommerce installed
- Dark Obsidian API key (orders + products + customers permissions)
- PHP 7.4+ on your WordPress server
- Products in Dark Obsidian - note their UUIDs or match by SKU
Option 1: PHP SDK (Recommended)
Drop the PHP SDK into your theme's functions.php or a custom plugin. This gives you full control and is the most reliable approach.
Step 1 - Download the SDK
Download DarkObsidian.php and place it in your theme or plugin directory.
Step 2 - Add to functions.php
<?php // In your theme's functions.php or a custom plugin file require_once get_template_directory() . '/DarkObsidian.php'; define('DO_API_KEY', 'do_live_YOUR_KEY_HERE'); // Never hardcode in production - use wp_options or environment variables: // define('DO_API_KEY', getenv('DO_API_KEY')); // Hook into WooCommerce order payment add_action('woocommerce_payment_complete', 'sync_order_to_dark_obsidian'); add_action('woocommerce_order_status_processing', 'sync_order_to_dark_obsidian'); function sync_order_to_dark_obsidian($order_id) { // Avoid double-sync if (get_post_meta($order_id, '_do_synced', true)) return; $order = wc_get_order($order_id); $client = new DarkObsidian(DO_API_KEY); // Build items array - match WooCommerce SKUs to Dark Obsidian product IDs $items = []; foreach ($order->get_items() as $item) { $product = $item->get_product(); $sku = $product ? $product->get_sku() : ''; $do_id = get_post_meta($product->get_id(), '_dark_obsidian_id', true); // If no stored ID, try looking up by SKU if (!$do_id && $sku) { $result = $client->request('GET', 'products', [], ['sku' => $sku]); $do_id = $result[0]['id'] ?? null; if ($do_id) update_post_meta($product->get_id(), '_dark_obsidian_id', $do_id); } if ($do_id) { $items[] = [ 'product_id' => $do_id, 'quantity' => $item->get_quantity(), 'unit_price' => (float) $item->get_subtotal() / $item->get_quantity(), ]; } } if (empty($items)) { error_log("Dark Obsidian: No matching products for order #{$order_id}"); return; } // Create the sale in Dark Obsidian try { $result = $client->orders->create([ 'customer' => [ 'name' => $order->get_formatted_billing_full_name(), 'email' => $order->get_billing_email(), 'phone' => $order->get_billing_phone(), ], 'items' => $items, 'payment_method' => $order->get_payment_method() ?: 'card', 'send_invoice' => false, // WooCommerce sends its own email 'notes' => "WooCommerce order #{$order->get_order_number()}", ]); // Store the Dark Obsidian order ID on the WooCommerce order update_post_meta($order_id, '_do_order_id', $result['order_id'] ?? ''); update_post_meta($order_id, '_do_synced', 'yes'); $order->add_order_note("Synced to Dark Obsidian: {$result['order_number']}"); } catch (Exception $e) { error_log("Dark Obsidian sync failed: " . $e->getMessage()); } }
Option 2: WooCommerce Webhooks + Your Server
If you prefer to handle the sync outside WordPress, use WooCommerce's built-in webhook system to POST to a separate Node.js / Python server.
https://yourserver.com/woo-webhookShow Live Inventory on Product Pages
Add this snippet to your WooCommerce single-product template to show live stock from Dark Obsidian:
<?php // single-product/stock.php override $product = wc_get_product(); $do_id = get_post_meta($product->get_id(), '_dark_obsidian_id', true); if ($do_id) { $client = new DarkObsidian(DO_API_KEY); $do_prod = $client->products->get($do_id); $stock = $do_prod['stock'] ?? 0; echo $stock > 0 ? "<span class='in-stock'>{$stock} in stock</span>" : "<span class='out-of-stock'>Out of stock</span>"; }
WordPress Plugin (Coming Soon)
We are building a dedicated WordPress plugin that adds a Dark Obsidian settings page to your WooCommerce admin. It will handle automatic product matching, order sync, and real-time stock display with zero code required.
Until then, the functions.php approach above is the recommended method. It takes less than 5 minutes.