Never Send the Referrer From Checkout and Account Pages
Sends a strict no-referrer policy on the WooCommerce checkout, order received and account pages, so order keys and other private URL details are never passed to third-party scripts or sites linked from there.
Opens WPIDE on
Code
add_action( 'template_redirect', function () {
if ( ! function_exists( 'is_checkout' ) || headers_sent() ) {
return;
}
if ( is_checkout() || is_account_page() || is_wc_endpoint_url( 'order-received' ) ) {
header( 'Referrer-Policy: no-referrer' );
add_action( 'wp_head', function () {
echo '<meta name="referrer" content="no-referrer">' . "\n";
}, 0 );
}
}, 20 );
Notes
Payment gateways that redirect off-site are not affected; they do not rely on the referrer.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.