WC_Widget_Brand_Nav::get_page_base_url()protectedWC 1.0

Get current page URL for layered nav items.

Method of the class: WC_Widget_Brand_Nav{}

No Hooks.

Return

String.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_page_base_url( $taxonomy );
$taxonomy(string) (required)
Taxonomy.

WC_Widget_Brand_Nav::get_page_base_url() code WC 9.5.1

protected function get_page_base_url( $taxonomy ) {
	if ( defined( 'SHOP_IS_ON_FRONT' ) ) {
		$link = home_url();
	} elseif ( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) {
		$link = get_post_type_archive_link( 'product' );
	} elseif ( is_product_category() ) {
		$link = get_term_link( get_query_var( 'product_cat' ), 'product_cat' );
	} elseif ( is_product_tag() ) {
		$link = get_term_link( get_query_var( 'product_tag' ), 'product_tag' );
	} else {
		$link = get_term_link( get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
	}
	// phpcs:disable WordPress.Security.NonceVerification.Recommended

	// Min/Max.
	if ( isset( $_GET['min_price'] ) ) {
		$link = add_query_arg( 'min_price', wc_clean( wp_unslash( $_GET['min_price'] ) ), $link );
	}

	if ( isset( $_GET['max_price'] ) ) {
		$link = add_query_arg( 'max_price', wc_clean( wp_unslash( $_GET['max_price'] ) ), $link );
	}

	// Orderby.
	if ( isset( $_GET['orderby'] ) ) {
		$link = add_query_arg( 'orderby', wc_clean( wp_unslash( $_GET['orderby'] ) ), $link );
	}

	/**
	 * Search Arg.
	 * To support quote characters, first they are decoded from " entities, then URL encoded.
	 */
	if ( get_search_query() ) {
		$link = add_query_arg( 's', rawurlencode( htmlspecialchars_decode( get_search_query() ) ), $link );
	}

	// Post Type Arg.
	if ( isset( $_GET['post_type'] ) ) {
		$link = add_query_arg( 'post_type', wc_clean( wp_unslash( $_GET['post_type'] ) ), $link );
	}

	// Min Rating Arg.
	if ( isset( $_GET['min_rating'] ) ) {
		$link = add_query_arg( 'min_rating', wc_clean( wp_unslash( $_GET['min_rating'] ) ), $link );
	}

	// All current filters.
	$_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes();
	if ( $_chosen_attributes ) {
		foreach ( $_chosen_attributes as $name => $data ) {
			if ( $name === $taxonomy ) {
				continue;
			}
			$filter_name = sanitize_title( str_replace( 'pa_', '', $name ) );
			if ( ! empty( $data['terms'] ) ) {
				$link = add_query_arg( 'filter_' . $filter_name, implode( ',', $data['terms'] ), $link );
			}
			if ( 'or' === $data['query_type'] ) {
				$link = add_query_arg( 'query_type_' . $filter_name, 'or', $link );
			}
		}
	}

	// phpcs:enable WordPress.Security.NonceVerification.Recommended
	return esc_url( $link );
}