By Devport Team | Last updated: 2025-07-12 | 17 min read

WooCommerce Multisite: Setup and Management Guide

Running multiple WooCommerce stores from a single WordPress installation offers powerful advantages for businesses managing multiple brands, regions, or product lines. This comprehensive guide covers everything from initial multisite setup to advanced management techniques, helping you build a scalable multi-store e-commerce platform.

Whether you're managing stores for different countries, creating a marketplace with multiple vendors, or operating various brand sites, WooCommerce multisite provides the flexibility and centralized control you need. We'll explore setup procedures, synchronization strategies, and management best practices that ensure smooth multi-store operations.

Table of Contents

  1. Multisite Architecture
  2. Setting Up WooCommerce Multisite
  3. Store Management and Configuration
  4. Shared Resources and Synchronization
  5. Performance and Scaling
  6. Security and Maintenance

Multisite Architecture

Understanding Multisite Structure

// Multisite configuration helper
class WC_Multisite_Configuration {

    /**
     * Initialize multisite configuration
     */
    public function __construct() {
        // Network-wide hooks
        add_action('init', [$this, 'setup_network_capabilities']);
        add_action('wpmu_new_blog', [$this, 'setup_new_store'], 10, 6);
        add_action('delete_blog', [$this, 'cleanup_store'], 10, 2);

        // Cross-site functionality
        add_filter('woocommerce_payment_gateways', [$this, 'network_payment_gateways']);
        add_filter('woocommerce_shipping_methods', [$this, 'network_shipping_methods']);

        // Admin interface
        add_action('network_admin_menu', [$this, 'add_network_menu']);
        add_action('admin_bar_menu', [$this, 'add_store_switcher'], 100);
    }

    /**
     * Setup network-wide capabilities
     */
    public function setup_network_capabilities() {
        // Define network-wide roles
        $network_caps = [
            'manage_network_stores' => true,
            'view_network_reports' => true,
            'manage_network_products' => true,
            'manage_network_orders' => true,
            'manage_network_customers' => true,
        ];

        // Add to super admin
        $role = get_role('administrator');
        foreach ($network_caps as $cap => $grant) {
            $role->add_cap($cap, $grant);
        }

        // Create network store manager role
        add_role('network_store_manager', 'Network Store Manager', [
            'read' => true,
            'manage_woocommerce' => true,
            'view_woocommerce_reports' => true,
            'manage_network_stores' => true,
            'switch_stores' => true,
        ]);
    }

    /**
     * Setup new store when created
     */
    public function setup_new_store($blog_id, $user_id, $domain, $path, $site_id, $meta) {
        switch_to_blog($blog_id);

        // Install WooCommerce tables
        $this->install_woocommerce_tables();

        // Configure default settings
        $this->configure_default_settings($meta);

        // Setup default pages
        $this->create_default_pages();

        // Configure permalinks
        $this->setup_permalinks();

        // Import shared products if enabled
        if (get_site_option('wc_multisite_shared_products')) {
            $this->import_shared_products();
        }

        // Trigger setup complete action
        do_action('wc_multisite_store_setup_complete', $blog_id);

        restore_current_blog();
    }

    /**
     * Configure default WooCommerce settings
     */
    private function configure_default_settings($meta) {
        // Get network defaults
        $network_settings = get_site_option('wc_multisite_default_settings', []);

        // Currency settings
        update_option('woocommerce_currency', $meta['currency'] ?? $network_settings['currency'] ?? 'USD');
        update_option('woocommerce_currency_pos', $network_settings['currency_pos'] ?? 'left');

        // Store settings
        update_option('woocommerce_store_address', $meta['address'] ?? '');
        update_option('woocommerce_store_city', $meta['city'] ?? '');
        update_option('woocommerce_store_postcode', $meta['postcode'] ?? '');
        update_option('woocommerce_default_country', $meta['country'] ?? 'US');

        // Tax settings
        update_option('woocommerce_calc_taxes', $network_settings['enable_taxes'] ?? 'no');
        update_option('woocommerce_tax_based_on', $network_settings['tax_based_on'] ?? 'shipping');

        // Shipping settings
        update_option('woocommerce_ship_to_countries', $network_settings['ship_to_countries'] ?? 'all');
        update_option('woocommerce_specific_ship_to_countries', $meta['ship_to_countries'] ?? []);

        // Payment settings
        update_option('woocommerce_default_gateway', $network_settings['default_gateway'] ?? 'stripe');

        // Email settings
        update_option('woocommerce_email_from_name', get_bloginfo('name'));
        update_option('woocommerce_email_from_address', get_option('admin_email'));
    }

    /**
     * Network-wide store management dashboard
     */
    public function render_network_dashboard() {
        $stores = get_sites([
            'public' => 1,
            'archived' => 0,
            'deleted' => 0,
        ]);

        ?>
        <div class="wrap">
            <h1>Network Store Management</h1>

            <div class="network-stats">
                <?php $this->render_network_statistics(); ?>
            </div>

            <table class="wp-list-table widefat fixed striped">
                <thead>
                    <tr>
                        <th>Store</th>
                        <th>URL</th>
                        <th>Products</th>
                        <th>Orders</th>
                        <th>Revenue</th>
                        <th>Status</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($stores as $store) : ?>
                        <?php $this->render_store_row($store); ?>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
        <?php
    }

    /**
     * Render individual store row
     */
    private function render_store_row($store) {
        switch_to_blog($store->blog_id);

        $products_count = wp_count_posts('product')->publish;
        $orders_count = wc_orders_count('completed');
        $revenue = $this->get_store_revenue();
        $status = get_option('woocommerce_store_status', 'active');

        restore_current_blog();

        ?>
        <tr>
            <td><?php echo esc_html($store->blogname); ?></td>
            <td>
                <a href="<?php echo esc_url($store->siteurl); ?>" target="_blank">
                    <?php echo esc_html($store->domain . $store->path); ?>
                </a>
            </td>
            <td><?php echo number_format($products_count); ?></td>
            <td><?php echo number_format($orders_count); ?></td>
            <td><?php echo wc_price($revenue); ?></td>
            <td>
                <span class="status-<?php echo esc_attr($status); ?>">
                    <?php echo esc_html(ucfirst($status)); ?>
                </span>
            </td>
            <td>
                <a href="<?php echo esc_url(get_admin_url($store->blog_id)); ?>" class="button">
                    Manage
                </a>
                <button class="button sync-store" data-store-id="<?php echo esc_attr($store->blog_id); ?>">
                    Sync
                </button>
            </td>
        </tr>
        <?php
    }
}

// Initialize multisite configuration
new WC_Multisite_Configuration();

Setting Up WooCommerce Multisite

Network Installation Process

// Multisite installation helper
class WC_Multisite_Installer {

    /**
     * Install multisite network
     */
    public static function install_network() {
        // Check if multisite is enabled
        if (!is_multisite()) {
            return new WP_Error('not_multisite', 'WordPress Multisite is not enabled');
        }

        // Create network tables
        self::create_network_tables();

        // Setup network options
        self::setup_network_options();

        // Configure network plugins
        self::configure_network_plugins();

        // Setup cron jobs
        self::setup_network_cron();

        return true;
    }

    /**
     * Create custom network tables
     */
    private static function create_network_tables() {
        global $wpdb;

        $charset_collate = $wpdb->get_charset_collate();

        // Shared products table
        $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->base_prefix}wc_shared_products (
            product_id bigint(20) NOT NULL,
            blog_id bigint(20) NOT NULL,
            shared_from bigint(20) NOT NULL,
            sync_price tinyint(1) DEFAULT 1,
            sync_stock tinyint(1) DEFAULT 1,
            sync_attributes tinyint(1) DEFAULT 1,
            last_sync datetime DEFAULT NULL,
            PRIMARY KEY (product_id, blog_id),
            KEY blog_id (blog_id),
            KEY shared_from (shared_from)
        ) $charset_collate;";

        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
        dbDelta($sql);

        // Network orders table
        $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->base_prefix}wc_network_orders (
            order_id bigint(20) NOT NULL,
            blog_id bigint(20) NOT NULL,
            customer_id bigint(20) NOT NULL,
            order_total decimal(10,2) NOT NULL,
            order_status varchar(20) NOT NULL,
            order_date datetime NOT NULL,
            PRIMARY KEY (order_id, blog_id),
            KEY customer_id (customer_id),
            KEY order_date (order_date)
        ) $charset_collate;";

        dbDelta($sql);

        // Shared inventory table
        $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->base_prefix}wc_shared_inventory (
            product_id bigint(20) NOT NULL,
            total_stock int(11) NOT NULL DEFAULT 0,
            reserved_stock int(11) NOT NULL DEFAULT 0,
            allocation_data longtext,
            last_updated datetime NOT NULL,
            PRIMARY KEY (product_id)
        ) $charset_collate;";

        dbDelta($sql);
    }

    /**
     * Setup network-wide options
     */
    private static function setup_network_options() {
        // Default settings for new stores
        add_site_option('wc_multisite_default_settings', [
            'currency' => 'USD',
            'currency_pos' => 'left',
            'thousand_sep' => ',',
            'decimal_sep' => '.',
            'num_decimals' => 2,
            'enable_taxes' => 'yes',
            'tax_based_on' => 'shipping',
            'shipping_tax_class' => 'standard',
            'ship_to_countries' => 'all',
            'default_gateway' => 'stripe',
            'enable_coupons' => 'yes',
            'calc_discounts_sequentially' => 'no',
        ]);

        // Network features
        add_site_option('wc_multisite_features', [
            'shared_products' => true,
            'shared_customers' => true,
            'shared_inventory' => false,
            'centralized_reporting' => true,
            'unified_analytics' => true,
            'cross_store_cart' => false,
        ]);

        // Store synchronization settings
        add_site_option('wc_multisite_sync_settings', [
            'auto_sync' => true,
            'sync_interval' => 'hourly',
            'sync_products' => true,
            'sync_orders' => true,
            'sync_customers' => true,
            'sync_inventory' => true,
        ]);
    }
}

// Activation hook
register_activation_hook(__FILE__, ['WC_Multisite_Installer', 'install_network']);

Store Creation Wizard

// Store creation wizard
class WC_Multisite_Store_Wizard {

    /**
     * Render store creation wizard
     */
    public function render_wizard() {
        $step = isset($_GET['step']) ? sanitize_key($_GET['step']) : 'basic';

        ?>
        <div class="wc-multisite-wizard">
            <h1>Create New Store</h1>

            <ul class="wizard-steps">
                <li class="<?php echo $step === 'basic' ? 'active' : ''; ?>">Basic Info</li>
                <li class="<?php echo $step === 'location' ? 'active' : ''; ?>">Location</li>
                <li class="<?php echo $step === 'products' ? 'active' : ''; ?>">Products</li>
                <li class="<?php echo $step === 'settings' ? 'active' : ''; ?>">Settings</li>
                <li class="<?php echo $step === 'review' ? 'active' : ''; ?>">Review</li>
            </ul>

            <form method="post" action="<?php echo admin_url('admin-post.php'); ?>">
                <?php wp_nonce_field('create_store', 'wc_multisite_nonce'); ?>
                <input type="hidden" name="action" value="create_multisite_store">
                <input type="hidden" name="step" value="<?php echo esc_attr($step); ?>">

                <?php $this->render_step($step); ?>

                <div class="wizard-buttons">
                    <?php if ($step !== 'basic') : ?>
                        <a href="<?php echo $this->get_step_url($this->get_previous_step($step)); ?>" class="button">
                            Previous
                        </a>
                    <?php endif; ?>

                    <?php if ($step !== 'review') : ?>
                        <button type="submit" class="button button-primary" name="save_step" value="next">
                            Next
                        </button>
                    <?php else : ?>
                        <button type="submit" class="button button-primary" name="save_step" value="create">
                            Create Store
                        </button>
                    <?php endif; ?>
                </div>
            </form>
        </div>
        <?php
    }

    /**
     * Render wizard step
     */
    private function render_step($step) {
        switch ($step) {
            case 'basic':
                $this->render_basic_step();
                break;
            case 'location':
                $this->render_location_step();
                break;
            case 'products':
                $this->render_products_step();
                break;
            case 'settings':
                $this->render_settings_step();
                break;
            case 'review':
                $this->render_review_step();
                break;
        }
    }

    /**
     * Create new store
     */
    public function create_store($data) {
        // Validate data
        $errors = $this->validate_store_data($data);
        if (!empty($errors)) {
            return new WP_Error('validation_failed', 'Store validation failed', $errors);
        }

        // Create site
        $site_id = wpmu_create_blog(
            $data['domain'],
            $data['path'],
            $data['title'],
            get_current_user_id(),
            [
                'public' => 1,
                'currency' => $data['currency'],
                'country' => $data['country'],
                'timezone' => $data['timezone'],
            ],
            get_current_network_id()
        );

        if (is_wp_error($site_id)) {
            return $site_id;
        }

        // Configure store
        switch_to_blog($site_id);

        // Set theme
        if (!empty($data['theme'])) {
            switch_theme($data['theme']);
        }

        // Configure WooCommerce
        $this->configure_woocommerce($data);

        // Import products
        if (!empty($data['import_products'])) {
            $this->import_products($data['import_products']);
        }

        restore_current_blog();

        return $site_id;
    }
}

Store Management and Configuration

Centralized Store Manager

// Centralized store management
class WC_Multisite_Store_Manager {

    /**
     * Get all network stores
     */
    public function get_network_stores($args = []) {
        $defaults = [
            'number' => 100,
            'public' => 1,
            'archived' => 0,
            'deleted' => 0,
        ];

        $args = wp_parse_args($args, $defaults);
        $sites = get_sites($args);

        $stores = [];
        foreach ($sites as $site) {
            switch_to_blog($site->blog_id);

            // Check if WooCommerce is active
            if (class_exists('WooCommerce')) {
                $stores[] = $this->get_store_data($site);
            }

            restore_current_blog();
        }

        return $stores;
    }

    /**
     * Get store data
     */
    private function get_store_data($site) {
        return [
            'id' => $site->blog_id,
            'name' => get_bloginfo('name'),
            'url' => $site->siteurl,
            'domain' => $site->domain,
            'path' => $site->path,
            'created' => $site->registered,
            'last_updated' => $site->last_updated,
            'products_count' => $this->get_products_count(),
            'orders_count' => $this->get_orders_count(),
            'customers_count' => $this->get_customers_count(),
            'revenue' => $this->get_total_revenue(),
            'currency' => get_woocommerce_currency(),
            'country' => WC()->countries->get_base_country(),
            'status' => $this->get_store_status(),
        ];
    }

    /**
     * Bulk update stores
     */
    public function bulk_update_stores($store_ids, $updates) {
        $results = [];

        foreach ($store_ids as $store_id) {
            switch_to_blog($store_id);

            try {
                // Update settings
                if (isset($updates['settings'])) {
                    foreach ($updates['settings'] as $key => $value) {
                        update_option($key, $value);
                    }
                }

                // Update products
                if (isset($updates['products'])) {
                    $this->bulk_update_products($updates['products']);
                }

                // Clear caches
                $this->clear_store_caches();

                $results[$store_id] = ['success' => true];

            } catch (Exception $e) {
                $results[$store_id] = [
                    'success' => false,
                    'error' => $e->getMessage(),
                ];
            }

            restore_current_blog();
        }

        return $results;
    }

    /**
     * Store health check
     */
    public function check_store_health($store_id) {
        switch_to_blog($store_id);

        $health = [
            'status' => 'healthy',
            'issues' => [],
            'warnings' => [],
        ];

        // Check database tables
        if (!$this->check_database_tables()) {
            $health['issues'][] = 'Missing WooCommerce database tables';
            $health['status'] = 'critical';
        }

        // Check required pages
        $required_pages = ['shop', 'cart', 'checkout', 'myaccount'];
        foreach ($required_pages as $page) {
            if (!wc_get_page_id($page)) {
                $health['warnings'][] = "Missing {$page} page";
                if ($health['status'] === 'healthy') {
                    $health['status'] = 'warning';
                }
            }
        }

        // Check payment gateways
        $gateways = WC()->payment_gateways()->get_available_payment_gateways();
        if (empty($gateways)) {
            $health['warnings'][] = 'No payment gateways enabled';
        }

        // Check shipping zones
        $zones = WC_Shipping_Zones::get_zones();
        if (empty($zones)) {
            $health['warnings'][] = 'No shipping zones configured';
        }

        // Check cron jobs
        if (!wp_next_scheduled('woocommerce_cleanup_sessions')) {
            $health['warnings'][] = 'WooCommerce cron jobs not scheduled';
        }

        restore_current_blog();

        return $health;
    }
}

Shared Resources and Synchronization

Product Synchronization System

// Product synchronization across stores
class WC_Multisite_Product_Sync {

    private $sync_fields = [
        'post_title',
        'post_content',
        'post_excerpt',
        'post_status',
        '_price',
        '_regular_price',
        '_sale_price',
        '_sku',
        '_stock',
        '_stock_status',
        '_weight',
        '_length',
        '_width',
        '_height',
    ];

    /**
     * Sync product to stores
     */
    public function sync_product($product_id, $target_stores, $options = []) {
        $source_blog_id = get_current_blog_id();
        $source_product = wc_get_product($product_id);

        if (!$source_product) {
            return new WP_Error('product_not_found', 'Source product not found');
        }

        $results = [];

        foreach ($target_stores as $store_id) {
            if ($store_id == $source_blog_id) {
                continue;
            }

            switch_to_blog($store_id);

            try {
                $synced_id = $this->sync_single_product($source_product, $source_blog_id, $options);
                $results[$store_id] = [
                    'success' => true,
                    'product_id' => $synced_id,
                ];
            } catch (Exception $e) {
                $results[$store_id] = [
                    'success' => false,
                    'error' => $e->getMessage(),
                ];
            }

            restore_current_blog();
        }

        return $results;
    }

    /**
     * Sync single product
     */
    private function sync_single_product($source_product, $source_blog_id, $options) {
        // Check if product already synced
        $existing_id = $this->get_synced_product_id($source_product->get_id(), $source_blog_id);

        if ($existing_id) {
            $product = wc_get_product($existing_id);
        } else {
            // Create new product
            $product_class = wc_get_product_classname($source_product->get_type());
            $product = new $product_class();
        }

        // Sync basic data
        $product->set_name($source_product->get_name());
        $product->set_description($source_product->get_description());
        $product->set_short_description($source_product->get_short_description());
        $product->set_status($source_product->get_status());

        // Sync prices if enabled
        if ($options['sync_prices'] ?? true) {
            $product->set_regular_price($source_product->get_regular_price());
            $product->set_sale_price($source_product->get_sale_price());
        }

        // Sync inventory if enabled
        if ($options['sync_inventory'] ?? true) {
            $product->set_manage_stock($source_product->get_manage_stock());
            $product->set_stock_quantity($source_product->get_stock_quantity());
            $product->set_stock_status($source_product->get_stock_status());
        }

        // Sync images
        if ($options['sync_images'] ?? true) {
            $this->sync_product_images($product, $source_product, $source_blog_id);
        }

        // Sync categories and tags
        if ($options['sync_taxonomies'] ?? true) {
            $this->sync_product_taxonomies($product, $source_product);
        }

        // Save product
        $product->save();

        // Store sync relationship
        $this->store_sync_relationship($product->get_id(), $source_product->get_id(), $source_blog_id);

        return $product->get_id();
    }

    /**
     * Real-time sync handler
     */
    public function setup_realtime_sync() {
        // Product update hooks
        add_action('woocommerce_update_product', [$this, 'handle_product_update'], 10, 2);
        add_action('woocommerce_new_product', [$this, 'handle_product_create'], 10, 2);
        add_action('before_delete_post', [$this, 'handle_product_delete']);

        // Stock update hooks
        add_action('woocommerce_product_set_stock', [$this, 'handle_stock_update']);
        add_action('woocommerce_variation_set_stock', [$this, 'handle_stock_update']);
    }

    /**
     * Handle product update
     */
    public function handle_product_update($product_id, $product) {
        // Check if real-time sync enabled
        if (!get_site_option('wc_multisite_realtime_sync', false)) {
            return;
        }

        // Get synced stores
        $synced_stores = $this->get_synced_stores($product_id);

        if (empty($synced_stores)) {
            return;
        }

        // Queue sync job
        as_enqueue_async_action('wc_multisite_sync_product', [
            'product_id' => $product_id,
            'source_blog_id' => get_current_blog_id(),
            'target_stores' => $synced_stores,
        ]);
    }
}

// Initialize product sync
new WC_Multisite_Product_Sync();

Shared Customer Management

// Shared customer database
class WC_Multisite_Customer_Manager {

    /**
     * Get network customer
     */
    public function get_network_customer($user_id) {
        $customer_data = [
            'id' => $user_id,
            'stores' => [],
            'total_orders' => 0,
            'total_spent' => 0,
            'average_order_value' => 0,
        ];

        // Get user data
        $user = get_user_by('id', $user_id);
        if (!$user) {
            return null;
        }

        $customer_data['email'] = $user->user_email;
        $customer_data['name'] = $user->display_name;
        $customer_data['registered'] = $user->user_registered;

        // Get data from each store
        $sites = get_sites();
        foreach ($sites as $site) {
            switch_to_blog($site->blog_id);

            if (class_exists('WooCommerce')) {
                $store_data = $this->get_customer_store_data($user_id);
                if ($store_data['order_count'] > 0) {
                    $customer_data['stores'][$site->blog_id] = $store_data;
                    $customer_data['total_orders'] += $store_data['order_count'];
                    $customer_data['total_spent'] += $store_data['total_spent'];
                }
            }

            restore_current_blog();
        }

        // Calculate average order value
        if ($customer_data['total_orders'] > 0) {
            $customer_data['average_order_value'] = $customer_data['total_spent'] / $customer_data['total_orders'];
        }

        return $customer_data;
    }

    /**
     * Sync customer data across stores
     */
    public function sync_customer_data($user_id, $data = []) {
        $sites = get_sites();

        foreach ($sites as $site) {
            switch_to_blog($site->blog_id);

            if (class_exists('WooCommerce')) {
                // Update billing information
                if (isset($data['billing'])) {
                    foreach ($data['billing'] as $key => $value) {
                        update_user_meta($user_id, 'billing_' . $key, $value);
                    }
                }

                // Update shipping information
                if (isset($data['shipping'])) {
                    foreach ($data['shipping'] as $key => $value) {
                        update_user_meta($user_id, 'shipping_' . $key, $value);
                    }
                }
            }

            restore_current_blog();
        }
    }
}

Performance and Scaling

Multisite Performance Optimization

// Multisite performance optimizer
class WC_Multisite_Performance {

    /**
     * Initialize performance optimizations
     */
    public function __construct() {
        // Database optimization
        add_action('init', [$this, 'optimize_queries']);

        // Caching strategies
        add_action('init', [$this, 'setup_caching']);

        // Resource management
        add_filter('woocommerce_product_query', [$this, 'optimize_product_queries']);

        // Lazy loading
        add_action('wp', [$this, 'setup_lazy_loading']);
    }

    /**
     * Optimize database queries
     */
    public function optimize_queries() {
        // Use persistent object cache
        if (function_exists('wp_cache_add_global_groups')) {
            wp_cache_add_global_groups([
                'wc_multisite_products',
                'wc_multisite_orders',
                'wc_multisite_customers',
            ]);
        }

        // Optimize autoloaded options
        $this->optimize_autoloaded_options();

        // Add database indexes
        $this->add_performance_indexes();
    }

    /**
     * Setup intelligent caching
     */
    public function setup_caching() {
        // Page cache rules
        if (!is_admin()) {
            // Cache product pages
            add_action('woocommerce_before_single_product', function() {
                if (!is_user_logged_in() && !WC()->cart->get_cart_contents_count()) {
                    header('Cache-Control: public, max-age=3600');
                }
            });

            // Don't cache dynamic pages
            add_action('template_redirect', function() {
                if (is_cart() || is_checkout() || is_account_page()) {
                    nocache_headers();
                }
            });
        }

        // Fragment caching
        add_filter('woocommerce_get_shop_page_id', [$this, 'cache_shop_page_id']);
    }

    /**
     * Network-wide performance monitoring
     */
    public function monitor_network_performance() {
        $metrics = [];
        $sites = get_sites();

        foreach ($sites as $site) {
            switch_to_blog($site->blog_id);

            $metrics[$site->blog_id] = [
                'response_time' => $this->measure_response_time(),
                'database_queries' => get_num_queries(),
                'memory_usage' => memory_get_peak_usage(true),
                'cache_hit_ratio' => $this->calculate_cache_hit_ratio(),
                'slow_queries' => $this->get_slow_queries_count(),
            ];

            restore_current_blog();
        }

        // Store metrics
        update_site_option('wc_multisite_performance_metrics', $metrics);

        // Alert if issues detected
        $this->check_performance_alerts($metrics);

        return $metrics;
    }
}

// Initialize performance optimizer
new WC_Multisite_Performance();

Security and Maintenance

Multisite Security Framework

// Multisite security implementation
class WC_Multisite_Security {

    /**
     * Initialize security measures
     */
    public function __construct() {
        // User permissions
        add_filter('user_has_cap', [$this, 'filter_capabilities'], 10, 4);

        // Data isolation
        add_action('pre_get_posts', [$this, 'enforce_data_isolation']);

        // Security monitoring
        add_action('wp_login', [$this, 'log_login_activity'], 10, 2);
        add_action('wp_login_failed', [$this, 'log_failed_login']);

        // Scheduled security tasks
        add_action('wc_multisite_security_scan', [$this, 'run_security_scan']);
    }

    /**
     * Run security scan across network
     */
    public function run_security_scan() {
        $issues = [];
        $sites = get_sites();

        foreach ($sites as $site) {
            switch_to_blog($site->blog_id);

            // Check file permissions
            $permission_issues = $this->check_file_permissions();
            if (!empty($permission_issues)) {
                $issues[$site->blog_id]['permissions'] = $permission_issues;
            }

            // Check for suspicious users
            $user_issues = $this->check_suspicious_users();
            if (!empty($user_issues)) {
                $issues[$site->blog_id]['users'] = $user_issues;
            }

            // Check plugin vulnerabilities
            $plugin_issues = $this->check_plugin_vulnerabilities();
            if (!empty($plugin_issues)) {
                $issues[$site->blog_id]['plugins'] = $plugin_issues;
            }

            restore_current_blog();
        }

        // Send security report
        if (!empty($issues)) {
            $this->send_security_alert($issues);
        }

        return $issues;
    }

    /**
     * Automated maintenance tasks
     */
    public function schedule_maintenance() {
        // Database optimization
        if (!wp_next_scheduled('wc_multisite_optimize_database')) {
            wp_schedule_event(time(), 'weekly', 'wc_multisite_optimize_database');
        }

        // Clear transients
        if (!wp_next_scheduled('wc_multisite_clear_transients')) {
            wp_schedule_event(time(), 'daily', 'wc_multisite_clear_transients');
        }

        // Backup verification
        if (!wp_next_scheduled('wc_multisite_verify_backups')) {
            wp_schedule_event(time(), 'daily', 'wc_multisite_verify_backups');
        }
    }
}

// Initialize security
new WC_Multisite_Security();

WooCommerce multisite provides a powerful platform for managing multiple stores efficiently. By implementing proper architecture, synchronization strategies, and management tools, you can create a scalable e-commerce network that maintains performance and security while providing centralized control over your entire operation.