From a0f47fb429266e1d55fbe5f77db928e478682973 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Fri, 1 Feb 2019 16:56:00 +0000 Subject: [PATCH] 404 on endpoints --- includes/wc-template-functions.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index 45d768b673f..55cf1e4a47e 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -42,7 +42,13 @@ function wc_template_redirect() { exit; } - } elseif ( is_search() && is_post_type_archive( 'product' ) && apply_filters( 'woocommerce_redirect_single_search_result', true ) && 1 === absint( $wp_query->found_posts ) ) { + // Trigger 404 if trying to access an endpoint on wrong page. + if ( is_wc_endpoint_url() && ! is_account_page() && ! is_checkout() ) { + $wp_query->set_404(); + status_header( 404 ); + include( get_query_template( '404' ) ); + exit; + } // Redirect to the product page if we have a single product. if ( is_search() && is_post_type_archive( 'product' ) && apply_filters( 'woocommerce_redirect_single_search_result', true ) && 1 === absint( $wp_query->found_posts ) ) {