get_var("SELECT COUNT(*) FROM {$wpdb->terms} t INNER JOIN {$wpdb->term_taxonomy} tt ON t.term_id = tt.term_id WHERE tt.taxonomy = 'yith_product_brand'"); $native_brands_before = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->terms} t INNER JOIN {$wpdb->term_taxonomy} tt ON t.term_id = tt.term_id WHERE tt.taxonomy = 'product_brand'"); echo " YITH 品牌数量: " . ($yith_brands_before ?: 0) . "\n"; echo " 原生品牌数量: " . ($native_brands_before ?: 0) . "\n\n"; if ($native_brands_before > 0) { echo "🔄 开始回滚原生品牌到 YITH 品牌...\n"; $wpdb->query('START TRANSACTION'); try { $result = $wpdb->update( $wpdb->term_taxonomy, array('taxonomy' => 'yith_product_brand'), array('taxonomy' => 'product_brand') ); if ($result !== false) { echo "✅ 成功回滚 " . $result . " 个品牌\n"; $wpdb->query('COMMIT'); wp_cache_flush(); if (function_exists('wc_delete_product_transients')) { wc_delete_product_transients(); } echo "✅ 缓存已清理\n"; $yith_brands_after = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->term_taxonomy} WHERE taxonomy = 'yith_product_brand'"); $native_brands_after = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->term_taxonomy} WHERE taxonomy = 'product_brand'"); echo "\n📊 回滚后数据统计:\n"; echo " YITH 品牌数量: " . ($yith_brands_after ?: 0) . "\n"; echo " 原生品牌数量: " . ($native_brands_after ?: 0) . "\n"; } else { $wpdb->query('ROLLBACK'); echo "❌ 回滚失败\n"; } } catch (Exception $e) { $wpdb->query('ROLLBACK'); echo "❌ 回滚出错: " . $e->getMessage() . "\n"; } } else { echo "ℹ️ 未检测到原生品牌数据,无需回滚\n"; } echo "\n=== 回滚完成 ===\n";