Fix shop page when using verbose page rules

cc @claudiosmweb
This commit is contained in:
Mike Jolley 2014-07-03 15:14:00 +01:00
parent 5946e3fd7c
commit a4346d9c90
2 changed files with 19 additions and 5 deletions

View File

@ -154,6 +154,19 @@ class WC_Query {
return; return;
} }
// Fix for verbose page rules
if ( $GLOBALS['wp_rewrite']->use_verbose_page_rules && isset( $q->queried_object_id ) && $q->queried_object_id === wc_get_page_id('shop') ) {
$q->set( 'post_type', 'product' );
$q->set( 'page', '' );
$q->set( 'pagename', '' );
// Fix conditional Functions
$q->is_archive = true;
$q->is_post_type_archive = true;
$q->is_singular = false;
$q->is_page = false;
}
// Fix for endpoints on the homepage // Fix for endpoints on the homepage
if ( $q->is_home() && 'page' == get_option('show_on_front') && get_option('page_on_front') != $q->get('page_id') ) { if ( $q->is_home() && 'page' == get_option('show_on_front') && get_option('page_on_front') != $q->get('page_id') ) {
$_query = wp_parse_args( $q->query ); $_query = wp_parse_args( $q->query );
@ -183,8 +196,9 @@ class WC_Query {
// This is a front-page shop // This is a front-page shop
$q->set( 'post_type', 'product' ); $q->set( 'post_type', 'product' );
$q->set( 'page_id', '' ); $q->set( 'page_id', '' );
if ( isset( $q->query['paged'] ) ) if ( isset( $q->query['paged'] ) ) {
$q->set( 'paged', $q->query['paged'] ); $q->set( 'paged', $q->query['paged'] );
}
// Define a variable so we know this is the front page shop later on // Define a variable so we know this is the front page shop later on
define( 'SHOP_IS_ON_FRONT', true ); define( 'SHOP_IS_ON_FRONT', true );
@ -194,7 +208,6 @@ class WC_Query {
global $wp_post_types; global $wp_post_types;
$shop_page = get_post( wc_get_page_id('shop') ); $shop_page = get_post( wc_get_page_id('shop') );
$q->is_page = true;
$wp_post_types['product']->ID = $shop_page->ID; $wp_post_types['product']->ID = $shop_page->ID;
$wp_post_types['product']->post_title = $shop_page->post_title; $wp_post_types['product']->post_title = $shop_page->post_title;
@ -206,6 +219,7 @@ class WC_Query {
$q->is_singular = false; $q->is_singular = false;
$q->is_post_type_archive = true; $q->is_post_type_archive = true;
$q->is_archive = true; $q->is_archive = true;
$q->is_page = true;
// Fix WP SEO // Fix WP SEO
if ( class_exists( 'WPSEO_Meta' ) ) { if ( class_exists( 'WPSEO_Meta' ) ) {

View File

@ -31,7 +31,7 @@ function wc_get_page_id( $page ) {
$page = apply_filters( 'woocommerce_get_' . $page . '_page_id', get_option('woocommerce_' . $page . '_page_id' ) ); $page = apply_filters( 'woocommerce_get_' . $page . '_page_id', get_option('woocommerce_' . $page . '_page_id' ) );
return $page ? $page : -1; return $page ? absint( $page ) : -1;
} }
/** /**