WC_Widget_Brand_Nav::get_page_base_url
Get current page URL for layered nav items.
Method of the class: WC_Widget_Brand_Nav{}
No Hooks.
Returns
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() WC Widget Brand Nav::get page base url code WC 10.4.3
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' );
} elseif ( is_tax() ) {
// Handle any taxonomy archive, including attributes
$queried_object = get_queried_object();
if ( is_null( $queried_object ) ) {
$link = get_post_type_archive_link( 'product' );
} else {
$link = get_term_link( $queried_object->term_id, $queried_object->taxonomy );
}
} else {
$link = get_post_type_archive_link( 'product' );
}
// 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 );
}
}
}
return $link;
}