How to integrate Odoo with Wordpress

Be smart, use SMART!


1. Define the Purpose of Integration

Decide what you aim to achieve with the integration:

  • Sync data between Odoo and WordPress (e.g., WooCommerce store integration).
  • Embed Odoo forms, such as contact forms or lead generation, into your WordPress site.
  • Display Odoo data on WordPress pages (e.g., product catalogs, order tracking).

2. Available Integration Methods

Option 1: Odoo-WooCommerce Connector

  • If your WordPress site uses WooCommerce, there are pre-built connectors that synchronize data between WooCommerce and Odoo:
    • Features:
      • Sync products, orders, and customers.
      • Automatic stock updates.

Steps to Use a WooCommerce Connector:

  1. Install the connector module in Odoo.
  2. Configure the WooCommerce API keys in WordPress.
  3. Map fields between Odoo and WooCommerce.
  4. Sync data as per your requirements.

Option 2: Embed Odoo Forms Using IFrames

  • If you want to integrate forms from Odoo (e.g., lead forms, contact forms):
    1. Create a form in Odoo (e.g., Website > Forms).
    2. Use the "Share" feature to generate an iframe link.
    3. Embed the iframe code into a WordPress page or post.

Option 3: Custom API Integration

  • For advanced use cases, you can use the Odoo REST API or XML-RPC API to integrate WordPress and Odoo.
    • Use Case: Fetch Odoo data and display it dynamically on WordPress, or push WordPress form submissions to Odoo (e.g., creating leads).

Steps:

  1. Enable Odoo API by ensuring xmlrpc is configured.
  2. Use a WordPress plugin like WP HTTP API or custom PHP scripts to connect to Odoo.
  3. Write API methods to handle data exchange (e.g., fetching products or creating records).

3. Available Plugins and Modules

WordPress Plugins

  1. WooCommerce Odoo Integration:
    • Plugins available on the WordPress plugin repository (search for "WooCommerce Odoo").
  2. Iframe Forms Plugin:

Odoo Apps

  1. Artarad WordPress Connector (Odoo App):
    • Synchronize WordPress posts with Odoo.
  2. Odoo WooCommerce Connector (Odoo App):
    • Sync WooCommerce store data with Odoo.

4. Example: Custom API Integration

Here’s how to integrate using Odoo’s REST API for fetching data dynamically.

1. Fetch Data from Odoo in WordPress:

  • Example PHP Code for WordPress:
    $url = 'https://your-odoo-instance.com';
    $db = 'your-database-name';
    $username = 'your-email@example.com';
    $password = 'your-password';
    
    // Authentication
    $common = ripcord::client("$url/xmlrpc/2/common");
    $uid = $common->authenticate($db, $username, $password, array());
    
    // Fetch Data
    $models = ripcord::client("$url/xmlrpc/2/object");
    $products = $models->execute_kw($db, $uid, $password,
        'product.template', 'search_read',
        array(array(array('sale_ok', '=', true))),
        array('fields'=>array('name', 'list_price'))
    );
    
    // Display Products
    foreach ($products as $product) {
        echo $product['name'] . ': $' . $product['list_price'] . '<br>';
    }
                            

2. Push Data from WordPress to Odoo:

    Example: Sending form data to Odoo (e.g., creating a lead):

    $lead_data = array(
        'name' => 'New Lead from WordPress',
        'email_from' => 'customer@example.com',
        'description' => 'Lead created via WordPress form.'
    );
    
    $lead_id = $models->execute_kw($db, $uid, $password,
        'crm.lead', 'create', array($lead_data)
    );
    
    echo "Lead created with ID: $lead_id";

5. Troubleshooting

  • Check API Logs: Enable logging in Odoo to monitor API requests.
  • Cross-Origin Issues: Use plugins like WP REST API CORS to handle cross-origin requests if embedding external forms.
  • Plugin Conflicts: Test integration plugins on a staging environment before deploying them live.

6. Conclusion

The integration method you choose depends on your use case:

  • Simple embedding: Use iframe forms.
  • WooCommerce store sync: Use connectors.
  • Advanced data sync: Use Odoo API with custom code.