WC_Cache_Helper::geolocation_ajax_redirect()
When using geolocation via ajax, to bust cache, redirect if the location hash does not equal the querystring.
Description Description
This prevents caching of the wrong data for this request.
Source Source
File: includes/class-wc-cache-helper.php
public static function geolocation_ajax_redirect() { if ( 'geolocation_ajax' === get_option( 'woocommerce_default_customer_address' ) && ! is_checkout() && ! is_cart() && ! is_account_page() && ! is_ajax() && empty( $_POST ) ) { // WPCS: CSRF ok, input var ok. $location_hash = self::geolocation_ajax_get_location_hash(); $current_hash = isset( $_GET['v'] ) ? wc_clean( wp_unslash( $_GET['v'] ) ) : ''; // WPCS: sanitization ok, input var ok, CSRF ok. if ( empty( $current_hash ) || $current_hash !== $location_hash ) { global $wp; $redirect_url = trailingslashit( home_url( $wp->request ) ); if ( ! empty( $_SERVER['QUERY_STRING'] ) ) { // WPCS: Input var ok. $redirect_url = add_query_arg( wp_unslash( $_SERVER['QUERY_STRING'] ), '', $redirect_url ); // WPCS: sanitization ok, Input var ok. } if ( ! get_option( 'permalink_structure' ) ) { $redirect_url = add_query_arg( $wp->query_string, '', $redirect_url ); } $redirect_url = add_query_arg( 'v', $location_hash, remove_query_arg( 'v', $redirect_url ) ); wp_safe_redirect( esc_url_raw( $redirect_url ), 307 ); exit; } } }