Преглед изворни кода

Merge pull request #181 from Automattic/radcliffe-2-jetpack-infinite-scroll-fix

Radcliffe 2: Fixes Jetpack Infinite Scroll on WooCommerce pages
Daniel Dudzic пре 7 година
родитељ
комит
b74850e011
3 измењених фајлова са 38 додато и 1 уклоњено
  1. 14 0
      radcliffe-2/inc/jetpack.php
  2. 23 0
      radcliffe-2/inc/woocommerce.php
  3. 1 1
      radcliffe-2/woocommerce.css

+ 14 - 0
radcliffe-2/inc/jetpack.php

@@ -56,14 +56,28 @@ add_action( 'after_setup_theme', 'radcliffe_2_jetpack_setup' );
  * Custom render function for Infinite Scroll.
  */
 function radcliffe_2_infinite_scroll_render() {
+
+	if ( class_exists( 'WooCommerce' ) && ( radcliffe_2_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
+		radcliffe_2_woocommerce_product_columns_wrapper();
+		woocommerce_product_loop_start();
+	}
+
 	while ( have_posts() ) {
 		the_post();
+
 		if ( is_search() ) :
 			get_template_part( 'template-parts/content', 'search' );
+		elseif ( class_exists( 'WooCommerce' ) && ( radcliffe_2_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) :
+			wc_get_template_part( 'content', 'product' );
 		else :
 			get_template_part( 'template-parts/content', get_post_format() );
 		endif;
 	}
+
+	if ( class_exists( 'WooCommerce' ) && ( radcliffe_2_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
+		woocommerce_product_loop_end();
+		radcliffe_2_woocommerce_product_columns_wrapper_close();
+	}
 }
 
 /**

+ 23 - 0
radcliffe-2/inc/woocommerce.php

@@ -318,6 +318,29 @@ remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 )
  */
 add_action( 'woocommerce_before_shop_loop', 'woocommerce_breadcrumb', 5 );
 
+/**
+ * Workaround to prevent is_shop() from failing due to WordPress core issue
+ *
+ * @link https://core.trac.wordpress.org/ticket/21790
+ * @param  array $args infinite scroll args.
+ * @return array       infinite scroll args.
+ */
+function radcliffe_2_woocommerce_is_shop_page() {
+	global $wp_query;
+
+	$front_page_id        = get_option( 'page_on_front' );
+	$current_page_id      = $wp_query->get( 'page_id' );
+	$is_static_front_page = 'page' === get_option( 'show_on_front' );
+
+	if ( $is_static_front_page && $front_page_id === $current_page_id  ) {
+		$is_shop_page = ( $current_page_id === wc_get_page_id( 'shop' ) ) ? true : false;
+	} else {
+		$is_shop_page = is_shop();
+	}
+
+	return $is_shop_page;
+}
+
 /**
  * Move the sale flash badge
  */

+ 1 - 1
radcliffe-2/woocommerce.css

@@ -360,7 +360,7 @@ ul.products li.product .button {
 	text-align: center;
 }
 
-.woocommerce-page #infinite-handle {
+.infinite-scroll .woocommerce-pagination {
 	display: none;
 }