WC_Cache_Helper::geolocation_ajax_redirect
When using geolocation via ajax, to bust cache, redirect if the location hash does not equal the querystring.
This prevents caching of the wrong data for this request.
Метод класса: WC_Cache_Helper{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$result = WC_Cache_Helper::geolocation_ajax_redirect();
Код WC_Cache_Helper::geolocation_ajax_redirect() WC Cache Helper::geolocation ajax redirect WC 11.2.2
public static function geolocation_ajax_redirect() {
if ( DefaultCustomerAddress::GEOLOCATION_AJAX === get_option( 'woocommerce_default_customer_address' ) && ! is_checkout() && ! is_cart() && ! is_account_page() && ! is_robots() && ! wp_doing_ajax() && empty( $_POST ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
$location_hash = self::geolocation_ajax_get_location_hash();
$current_hash = isset( $_GET['v'] ) ? wc_clean( wp_unslash( $_GET['v'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Hash is cleaned; same-site redirect uses esc_url_raw() and wp_safe_redirect().
if ( empty( $current_hash ) || $current_hash !== $location_hash ) {
global $wp;
$redirect_url = trailingslashit( home_url( $wp->request ) );
if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
$redirect_url = add_query_arg( wp_unslash( $_SERVER['QUERY_STRING'] ), '', $redirect_url ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Hash is cleaned; same-site redirect uses esc_url_raw() and wp_safe_redirect().
}
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( array( 'v', 'add-to-cart' ), $redirect_url ) );
wp_safe_redirect( esc_url_raw( $redirect_url ), 307 );
exit;
}
}
}