// 阻止 WooCommerce 初始化 session(减少写库) add_action( 'init', function() { if ( is_admin() ) return; $ua = isset($_SERVER['HTTP_USER_AGENT']) ? strtolower($_SERVER['HTTP_USER_AGENT']) : ''; $is_bot = preg_match('/bot|spider|crawl|slurp|bingpreview|facebookexternalhit|pinterest|ahrefs|semrush|mj12|dotbot|petalbot|bytespider/i', $ua); if ( $is_bot ) { // 阻止 WooCommerce 初始化 session(减少写库) remove_action( 'wp_loaded', [ 'WC_Session_Handler', 'init' ], 10 ); if ( function_exists('WC') && WC()->session ) { WC()->session = null; } } }, 1 );