api_key = $api_key; } public static function register_wc_webhooks() { if (!class_exists('WC_Webhook')) return; $api_key = get_option('addtaisa_api_key'); if (!$api_key) return; $topics = [ 'product.created', 'product.updated', 'product.deleted', 'order.created', 'order.updated', ]; foreach ($topics as $topic) { $webhook = new WC_Webhook(); $webhook->set_name('AddToChat - ' . $topic); $webhook->set_topic($topic); $webhook->set_delivery_url(ADDTAISA_API_URL . '/v1/catalog/webhooks/woo/' . $api_key); $webhook->set_status('active'); $webhook->set_secret(wp_generate_password(50, false)); $webhook->save(); } } public static function unregister_wc_webhooks() { $webhooks = wc_get_webhooks(); foreach ($webhooks as $webhook_id) { $webhook = wc_get_webhook($webhook_id); if ($webhook && strpos($webhook->get_name(), 'AddToChat') !== false) { $webhook->delete(true); } } } }