From e81c018e6065eef2299c2a039059bcd1793fe88b Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 3 Mar 2014 11:54:49 +0000 Subject: [PATCH] wc_get_endpoint_url - added support for permalinks containing a query string Closes #5016 --- includes/wc-page-functions.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/includes/wc-page-functions.php b/includes/wc-page-functions.php index 8e3fc57ab50..5faf67b8302 100644 --- a/includes/wc-page-functions.php +++ b/includes/wc-page-functions.php @@ -49,10 +49,17 @@ function wc_get_endpoint_url( $endpoint, $value = '', $permalink = '' ) { // Map endpoint to options $endpoint = isset( WC()->query->query_vars[ $endpoint ] ) ? WC()->query->query_vars[ $endpoint ] : $endpoint; - if ( get_option( 'permalink_structure' ) ) - $url = trailingslashit( $permalink ) . $endpoint . '/' . $value; - else + if ( get_option( 'permalink_structure' ) ) { + if ( strstr( $permalink, '?' ) ) { + $query_string = '?' . parse_url( $permalink, PHP_URL_QUERY ); + $permalink = current( explode( '?', $permalink ) ); + } else { + $query_string = ''; + } + $url = trailingslashit( $permalink ) . $endpoint . '/' . $value . $query_string; + } else { $url = add_query_arg( $endpoint, $value, $permalink ); + } return apply_filters( 'woocommerce_get_endpoint_url', $url ); }