// 阻止 WooCommerce 初始化 session(减少写库) add_action('wp_loaded', function () { if ( is_admin() ) return; if ( defined('DOING_CRON') && DOING_CRON ) return; // Detect bots $ua = isset($_SERVER['HTTP_USER_AGENT']) ? strtolower($_SERVER['HTTP_USER_AGENT']) : ''; $is_bot = (bool) preg_match('/bot|spider|crawl|slurp|bingpreview|facebookexternalhit|pinterest|ahrefs|semrush|mj12|dotbot|petalbot|bytespider|yandex/i', $ua); // Decide if this request really needs Woo session $need_session = ( function_exists('is_cart') && is_cart() ) || ( function_exists('is_checkout') && is_checkout() ) || ( function_exists('is_account_page') && is_account_page() ); // Woo add-to-cart / wc-ajax should keep session if ( isset($_REQUEST['add-to-cart']) || isset($_REQUEST['wc-ajax']) ) { $need_session = true; } // If user already has cart cookies, keep session (returning customer) if ( isset($_COOKIE['woocommerce_items_in_cart']) || isset($_COOKIE['woocommerce_cart_hash']) ) { $need_session = true; } // Bots should never create sessions if ( $is_bot ) { $need_session = false; } // Disable session writes if not needed if ( ! $need_session && function_exists('WC') && WC()->session ) { WC()->session = null; } }, 1); Litech Power ,LiTech Power

Informazioni su Litech Power

L'autore non ha ancora inserito alcun dettaglio.
Finora Litech Power ha creato 0 voci di blog.
返回顶部