Files
WooDoo/woodoo.php
Malin 68c1ff4455 feat: initial WooDoo plugin – WooCommerce & Odoo 19 integration
- Odoo JSON-RPC client (no Composer, uses wp_remote_post)
- Admin settings page under WooCommerce with connection test
- Customer linking: search Odoo partners from WP user profile
- My Account: Odoo Invoices tab with PDF proxy download
- My Account: Book a Meeting tab (slot calculator + calendar.event)
- WC order → Odoo sale.order auto-sync on processing status
- Products matched by SKU; partner auto-created from billing info
- Uninstall cleanup (options, user meta, order meta, DB table)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-01 13:58:27 +02:00

124 lines
4.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Plugin Name: WooDoo WooCommerce & Odoo Integration
* Plugin URI: https://github.com/
* Description: Connects WooCommerce to a self-hosted Odoo 19 instance. Customer linking, invoices, meeting booking, and automatic sales order creation.
* Version: 1.0.0
* Requires at least: 6.0
* Requires PHP: 8.1
* Author: WooDoo
* License: GPL v2 or later
* Text Domain: woodoo
*/
defined( 'ABSPATH' ) || exit;
define( 'WOODOO_VERSION', '1.0.0' );
define( 'WOODOO_FILE', __FILE__ );
define( 'WOODOO_DIR', plugin_dir_path( __FILE__ ) );
define( 'WOODOO_URL', plugin_dir_url( __FILE__ ) );
// ── Auto-load includes ──────────────────────────────────────────────────────
foreach ( [
'class-woodoo-api',
'class-woodoo-admin',
'class-woodoo-invoices',
'class-woodoo-calendar',
'class-woodoo-orders',
] as $file ) {
require_once WOODOO_DIR . 'includes/' . $file . '.php';
}
// ── Frontend Assets ───────────────────────────────────────────────────────────
add_action( 'wp_enqueue_scripts', 'woodoo_register_frontend_assets' );
function woodoo_register_frontend_assets(): void {
wp_register_style(
'woodoo-frontend',
WOODOO_URL . 'assets/css/woodoo.css',
[],
WOODOO_VERSION
);
wp_register_script(
'woodoo-frontend',
WOODOO_URL . 'assets/js/woodoo-frontend.js',
[],
WOODOO_VERSION,
true
);
}
// ── Boot ─────────────────────────────────────────────────────────────────────
add_action( 'plugins_loaded', 'woodoo_init' );
function woodoo_init(): void {
if ( ! class_exists( 'WooCommerce' ) ) {
add_action( 'admin_notices', fn() =>
print '<div class="notice notice-error"><p>' .
esc_html__( 'WooDoo requires WooCommerce to be active.', 'woodoo' ) .
'</p></div>'
);
return;
}
WooDoo_Admin::init();
WooDoo_Invoices::init();
WooDoo_Calendar::init();
WooDoo_Orders::init();
}
/**
* Returns a configured WooDoo_API instance using saved options.
* Returns null if credentials are not set.
*/
function woodoo_api(): ?WooDoo_API {
static $instance = null;
if ( $instance ) return $instance;
$opts = [
'url' => get_option( 'woodoo_odoo_url', '' ),
'db' => get_option( 'woodoo_odoo_db', '' ),
'username' => get_option( 'woodoo_odoo_username', '' ),
'api_key' => get_option( 'woodoo_odoo_api_key', '' ),
];
foreach ( $opts as $v ) {
if ( empty( $v ) ) return null;
}
$instance = new WooDoo_API(
rtrim( $opts['url'], '/' ),
$opts['db'],
$opts['username'],
$opts['api_key']
);
return $instance;
}
// ── Activation / Deactivation ─────────────────────────────────────────────
register_activation_hook( __FILE__, 'woodoo_activate' );
function woodoo_activate(): void {
// Create DB table for customer links (supplement to user meta)
global $wpdb;
$table = $wpdb->prefix . 'woodoo_customer_links';
$charset = $wpdb->get_charset_collate();
$sql = "CREATE TABLE IF NOT EXISTS {$table} (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
wp_user_id BIGINT UNSIGNED NOT NULL,
odoo_partner_id INT UNSIGNED NOT NULL,
linked_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY wp_user_id (wp_user_id),
KEY odoo_partner_id (odoo_partner_id)
) {$charset};";
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta( $sql );
// Register endpoints and flush so My Account tabs appear immediately
WC()->query->init_query_vars();
WC()->query->add_endpoints();
flush_rewrite_rules();
}