Skip to content

Commit 9f61045

Browse files
committed
Set header cache-control for cart/checkout pages closes #29484
1 parent 6782177 commit 9f61045

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

includes/class-wc-cache-helper.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,34 @@ public static function init() {
4242
*/
4343
public static function additional_nocache_headers( $headers ) {
4444
$agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
45+
46+
$set_cache = false;
47+
4548
/**
4649
* Allow plugins to enable nocache headers. Enabled for Google weblight.
4750
*
48-
* @see https://support.google.com/webmasters/answer/1061943?hl=en
4951
* @param bool $enable_nocache_headers Flag indicating whether to add nocache headers. Default: false.
5052
*/
51-
if ( false !== strpos( $agent, 'googleweblight' ) || apply_filters( 'woocommerce_enable_nocache_headers', false ) ) {
53+
if ( apply_filters( 'woocommerce_enable_nocache_headers', false ) ) {
54+
$set_cache = true;
55+
}
56+
57+
/**
58+
* Enabled for Google weblight.
59+
*
60+
* @see https://support.google.com/webmasters/answer/1061943?hl=en
61+
*/
62+
if ( false !== strpos( $agent, 'googleweblight' ) ) {
5263
// no-transform: Opt-out of Google weblight. https://support.google.com/webmasters/answer/6211428?hl=en.
64+
$set_cache = true;
65+
}
66+
67+
// Note that is_cart() will return true even for checkout page.
68+
if ( false !== strpos( $agent, 'Chrome' ) && is_cart() ) {
69+
$set_cache = true;
70+
}
71+
72+
if ( $set_cache ) {
5373
$headers['Cache-Control'] = 'no-transform, no-cache, no-store, must-revalidate';
5474
}
5575
return $headers;

0 commit comments

Comments
 (0)