query( $wpdb->prepare( " DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b WHERE ( a.option_name LIKE %s OR a.option_name LIKE %s ) AND a.option_name NOT LIKE '\_transient\_timeout\_%%' AND a.option_name NOT LIKE '\_site\_transient\_timeout\_%%' AND ( b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, CHAR_LENGTH('_transient_') + 1 ) ) OR b.option_name = CONCAT( '_site_transient_timeout_', SUBSTRING( a.option_name, CHAR_LENGTH('_site_transient_') + 1 ) ) ) ", "\_transient\_%" . $version, "\_site\_transient\_%" . $version ) ); } } /** * Get the page name/id for a WC page * @param string $wc_page * @return array */ private static function get_page_uris( $wc_page ) { $wc_page_uris = array(); if ( ( $page_id = wc_get_page_id( $wc_page ) ) && $page_id > 0 && ( $page = get_post( $page_id ) ) ) { $wc_page_uris[] = 'p=' . $page_id; $wc_page_uris[] = '/' . $page->post_name; } return $wc_page_uris; } /** * Prevent caching on dynamic pages. * * @access public * @return void */ public static function prevent_caching() { if ( false === ( $wc_page_uris = get_transient( 'woocommerce_cache_excluded_uris' ) ) ) { $wc_page_uris = array_filter( array_merge( self::get_page_uris( 'cart' ), self::get_page_uris( 'checkout' ), self::get_page_uris( 'myaccount' ) ) ); set_transient( 'woocommerce_cache_excluded_uris', $wc_page_uris ); } if ( is_array( $wc_page_uris ) ) { foreach( $wc_page_uris as $uri ) { if ( strstr( $_SERVER['REQUEST_URI'], $uri ) ) { self::nocache(); break; } } } } /** * Set nocache constants and headers. * * @access private * @return void */ private static function nocache() { if ( ! defined( 'DONOTCACHEPAGE' ) ) define( "DONOTCACHEPAGE", "true" ); if ( ! defined( 'DONOTCACHEOBJECT' ) ) define( "DONOTCACHEOBJECT", "true" ); if ( ! defined( 'DONOTCACHEDB' ) ) define( "DONOTCACHEDB", "true" ); nocache_headers(); } /** * notices function. * * @access public * @return void */ public static function notices() { if ( ! function_exists( 'w3tc_pgcache_flush' ) || ! function_exists( 'w3_instance' ) ) { return; } $config = w3_instance('W3_Config'); $enabled = $config->get_integer( 'dbcache.enabled' ); $settings = array_map( 'trim', $config->get_array( 'dbcache.reject.sql' ) ); if ( $enabled && ! in_array( '_wc_session_', $settings ) ) { ?>

database caching to work with WooCommerce you must add _wc_session_ to the "Ignored Query Strings" option in W3 Total Cache settings here.', 'woocommerce' ), admin_url( 'admin.php?page=w3tc_dbcache' ) ); ?>