Fix shop on homepage with unsupported themes
This commit is contained in:
parent
2d8d5f3fdb
commit
2ed9691c14
|
@ -71,7 +71,6 @@ class WC_Query {
|
|||
public function init_query_vars() {
|
||||
// Query vars to add to WP.
|
||||
$this->query_vars = array(
|
||||
'product-page' => '',
|
||||
// Checkout actions.
|
||||
'order-pay' => get_option( 'woocommerce_checkout_pay_endpoint', 'order-pay' ),
|
||||
'order-received' => get_option( 'woocommerce_checkout_order_received_endpoint', 'order-received' ),
|
||||
|
@ -277,14 +276,20 @@ class WC_Query {
|
|||
}
|
||||
}
|
||||
|
||||
// When orderby is set, WordPress shows posts. Get around that here.
|
||||
// When orderby is set, WordPress shows posts on the front-page. Get around that here.
|
||||
if ( $this->is_showing_page_on_front( $q ) && $this->page_on_front_is( wc_get_page_id( 'shop' ) ) ) {
|
||||
$_query = wp_parse_args( $q->query );
|
||||
if ( empty( $_query ) || ! array_diff( array_keys( $_query ), array( 'preview', 'page', 'paged', 'cpage', 'orderby' ) ) ) {
|
||||
$q->set( 'page_id', (int) get_option( 'page_on_front' ) );
|
||||
$q->is_page = true;
|
||||
$q->is_home = false;
|
||||
$q->set( 'page_id', (int) get_option( 'page_on_front' ) );
|
||||
$q->set( 'post_type', 'product' );
|
||||
|
||||
// WP supporting themes show post type archive.
|
||||
if ( current_theme_supports( 'woocommerce' ) ) {
|
||||
$q->set( 'post_type', 'product' );
|
||||
} else {
|
||||
$q->is_singular = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -293,8 +298,8 @@ class WC_Query {
|
|||
$q->is_comment_feed = false;
|
||||
}
|
||||
|
||||
// Special check for shops with the product archive on front.
|
||||
if ( $q->is_page() && 'page' === get_option( 'show_on_front' ) && absint( $q->get( 'page_id' ) ) === wc_get_page_id( 'shop' ) ) {
|
||||
// Special check for shops with the PRODUCT POST TYPE ARCHIVE on front.
|
||||
if ( current_theme_supports( 'woocommerce' ) && $q->is_page() && 'page' === get_option( 'show_on_front' ) && absint( $q->get( 'page_id' ) ) === wc_get_page_id( 'shop' ) ) {
|
||||
// This is a front-page shop.
|
||||
$q->set( 'post_type', 'product' );
|
||||
$q->set( 'page_id', '' );
|
||||
|
|
|
@ -370,7 +370,11 @@ class WC_Template_Loader {
|
|||
* @return string
|
||||
*/
|
||||
public static function unsupported_theme_title_filter( $title, $id ) {
|
||||
if ( ! self::$theme_support && is_page( self::$shop_page_id ) && $id === self::$shop_page_id ) {
|
||||
if ( self::$theme_support || ! $id !== self::$shop_page_id ) {
|
||||
return $title;
|
||||
}
|
||||
|
||||
if ( is_page( self::$shop_page_id ) || ( is_home() && 'page' === get_option( 'show_on_front' ) && absint( get_option( 'page_on_front' ) ) === self::$shop_page_id ) ) {
|
||||
$args = self::get_current_shop_view_args();
|
||||
$title_suffix = array();
|
||||
|
||||
|
|
|
@ -179,7 +179,7 @@ class WC_Shortcode_Products {
|
|||
);
|
||||
|
||||
if ( wc_string_to_bool( $this->attributes['paginate'] ) ) {
|
||||
$this->attributes['page'] = get_query_var( 'product-page', 1 );
|
||||
$this->attributes['page'] = absint( empty( $_GET['product-page'] ) ? 1 : $_GET['product-page'] ); // WPCS: input var ok, CSRF ok.
|
||||
}
|
||||
|
||||
if ( ! empty( $this->attributes['rows'] ) ) {
|
||||
|
|
|
@ -84,7 +84,7 @@ class WC_Widget_Price_Filter extends WC_Widget {
|
|||
$this->widget_start( $args, $instance );
|
||||
|
||||
if ( '' === get_option( 'permalink_structure' ) ) {
|
||||
$form_action = remove_query_arg( array( 'page', 'paged' ), add_query_arg( $wp->query_string, '', home_url( $wp->request ) ) );
|
||||
$form_action = remove_query_arg( array( 'page', 'paged', 'product-page' ), add_query_arg( $wp->query_string, '', home_url( $wp->request ) ) );
|
||||
} else {
|
||||
$form_action = preg_replace( '%\/page/[0-9]+%', '', home_url( trailingslashit( $wp->request ) ) );
|
||||
}
|
||||
|
|
|
@ -28,5 +28,5 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
<?php endforeach; ?>
|
||||
</select>
|
||||
<input type="hidden" name="paged" value="1" />
|
||||
<?php wc_query_string_form_fields( null, array( 'orderby', 'submit', 'paged' ) ); ?>
|
||||
<?php wc_query_string_form_fields( null, array( 'orderby', 'submit', 'paged', 'product-page' ) ); ?>
|
||||
</form>
|
||||
|
|
|
@ -43,8 +43,7 @@ class WC_Tests_WC_Query extends WC_Unit_Test_Case {
|
|||
// Test the default options are present.
|
||||
WC()->query->init_query_vars();
|
||||
$default_vars = WC()->query->get_query_vars();
|
||||
$expected = array(
|
||||
'product-page' => '',
|
||||
$expected = array(
|
||||
'order-pay' => 'order-pay',
|
||||
'order-received' => 'order-received',
|
||||
'orders' => 'orders',
|
||||
|
|
Loading…
Reference in New Issue