浏览代码

Merge pull request #172 from Automattic/jetpack_infinite_scroll_wc_products_fixes

Jetpack infinite scroll wc products fixes
Jeffrey Pearce 7 年之前
父节点
当前提交
ade3f0d22a

+ 3 - 1
button-2/inc/jetpack.php

@@ -75,7 +75,9 @@ function button_2_infinite_scroll_render() {
 	while ( have_posts() ) {
 		the_post();
 
-		if ( class_exists( 'WooCommerce' ) && ( is_shop() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) :
+		if ( is_search() ) :
+			get_template_part( 'components/content', 'search' );
+		elseif ( class_exists( 'WooCommerce' ) && ( is_shop() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) :
 			wc_get_template_part( 'content', 'product' );
 		else :
 			get_template_part( 'components/content', get_post_format() );

+ 8 - 25
button-2/inc/woocommerce.php

@@ -83,9 +83,11 @@ add_filter( 'body_class', 'button_2_woocommerce_active_body_class' );
  * @return integer number of products.
  */
 function button_2_woocommerce_products_per_page() {
-	return 12;
+	return absint( apply_filters( 'button_2_woocommerce_products_per_page', 12 ) );
+}
+if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '3.3', '<' ) ) {
+	add_filter( 'loop_shop_per_page', 'button_2_woocommerce_products_per_page' );
 }
-add_filter( 'loop_shop_per_page', 'button_2_woocommerce_products_per_page' );
 
 /**
  * Product gallery thumnbail columns.
@@ -93,7 +95,7 @@ add_filter( 'loop_shop_per_page', 'button_2_woocommerce_products_per_page' );
  * @return integer number of columns.
  */
 function button_2_woocommerce_thumbnail_columns() {
-	return 4;
+	return absint( apply_filters( 'button_2_woocommerce_product_thumbnail_columns', 4 ) );
 }
 add_filter( 'woocommerce_product_thumbnails_columns', 'button_2_woocommerce_thumbnail_columns' );
 
@@ -103,7 +105,7 @@ add_filter( 'woocommerce_product_thumbnails_columns', 'button_2_woocommerce_thum
  * @return integer products per row.
  */
 function button_2_woocommerce_loop_columns() {
-	return 3;
+	return absint( apply_filters( 'button_2_woocommerce_loop_columns', 3 ) );
 }
 add_filter( 'loop_shop_columns', 'button_2_woocommerce_loop_columns' );
 
@@ -114,12 +116,10 @@ add_filter( 'loop_shop_columns', 'button_2_woocommerce_loop_columns' );
  * @return array $args related products args.
  */
 function button_2_woocommerce_related_products_args( $args ) {
-	$defaults = array(
+	$args = apply_filters( 'radcliffe_2_woocommerce_related_products_args', array(
 		'posts_per_page' => 3,
 		'columns'        => 3,
-	);
-
-	$args = wp_parse_args( $defaults, $args );
+	) );
 
 	return $args;
 }
@@ -281,23 +281,6 @@ function button_2_woocommerce_is_shop_page() {
 	return $is_shop_page;
 }
 
-/**
- * Jetpack infinite scroll duplicates posts where orderby is anything other than modified or date
- * This filter offsets the products returned by however many are displayed per page
- *
- * @link https://github.com/Automattic/jetpack/issues/1135
- * @param  array $args infinite scroll args.
- * @return array       infinite scroll args.
- */
-function button_2_woocommerce_jetpack_duplicate_products( $args ) {
-	if ( ( isset( $args['post_type'] ) && 'product' === $args['post_type'] ) || ( isset( $args['taxonomy'] ) && 'product_cat' === $args['taxonomy'] ) ) {
-		$args['offset'] = $args['posts_per_page'] * $args['paged'];
-	}
-
- 	return $args;
-}
-add_filter( 'infinite_scroll_query_args', 'button_2_woocommerce_jetpack_duplicate_products', 100 );
-
 /**
  * Override number of products per page in Jetpack infinite scroll.
  *

+ 1 - 1
button-2/style.css

@@ -4,7 +4,7 @@ Theme URI: http://wordpress.com/themes/button-2/
 Author: Automattic
 Author URI: http://automattic.com
 Description: A stylish, lighthearted theme for crafters, hobbyists, and creatives.
-Version: 2.1.2-wpcom
+Version: 2.1.3-wpcom
 License: GNU General Public License v2 or later
 License URI: http://www.gnu.org/licenses/gpl-2.0.html
 Text Domain: button

+ 1 - 1
dara/inc/woocommerce.php

@@ -327,4 +327,4 @@ function dara_woocommerce_is_shop_page() {
 	}
 
 	return $is_shop_page;
-}
+}

+ 8 - 24
karuna/inc/woocommerce.php

@@ -111,7 +111,10 @@ add_filter( 'body_class', 'karuna_woocommerce_active_body_class' );
  * @return integer number of products.
  */
 function karuna_woocommerce_products_per_page() {
-	return 12;
+	return absint( apply_filters( 'karuna_woocommerce_products_per_page', 12 ) );
+}
+if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '3.3', '<' ) ) {
+	add_filter( 'loop_shop_per_page', 'karuna_woocommerce_products_per_page' );
 }
 
 // Legacy WooCommerce products per page filter.
@@ -125,7 +128,7 @@ if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '3.3', '<' ) ) {
  * @return integer number of columns.
  */
 function karuna_woocommerce_thumbnail_columns() {
-	return 4;
+	return absint( apply_filters( 'karuna_woocommerce_product_thumbnail_columns', 4 ) );
 }
 add_filter( 'woocommerce_product_thumbnails_columns', 'karuna_woocommerce_thumbnail_columns' );
 
@@ -135,7 +138,7 @@ add_filter( 'woocommerce_product_thumbnails_columns', 'karuna_woocommerce_thumbn
  * @return integer products per row.
  */
 function karuna_woocommerce_loop_columns() {
-	return 2;
+	return absint( apply_filters( 'karuna_woocommerce_loop_columns', 2 ) );
 }
 
 // Legacy WooCommerce columns filter.
@@ -150,12 +153,10 @@ if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '3.3', '<' ) ) {
  * @return array $args related products args.
  */
 function karuna_woocommerce_related_products_args( $args ) {
-	$defaults = array(
+	$args = apply_filters( 'karuna_woocommerce_related_products_args', array(
 		'posts_per_page' => 2,
 		'columns'        => 2,
-	);
-
-	$args = wp_parse_args( $defaults, $args );
+	) );
 
 	return $args;
 }
@@ -347,23 +348,6 @@ function karuna_woocommerce_is_shop_page() {
 	return $is_shop_page;
 }
 
-/**
- * Jetpack infinite scroll duplicates posts where orderby is anything other than modified or date
- * This filter offsets the products returned by however many are displayed per page
- *
- * @link https://github.com/Automattic/jetpack/issues/1135
- * @param  array $args infinite scroll args.
- * @return array       infinite scroll args.
- */
-function karuna_woocommerce_jetpack_duplicate_products( $args ) {
-	if ( ( isset( $args['post_type'] ) && 'product' === $args['post_type'] ) || ( isset( $args['taxonomy'] ) && 'product_cat' === $args['taxonomy'] ) ) {
-		$args['offset'] = $args['posts_per_page'] * $args['paged'];
-	}
-
- 	return $args;
-}
-add_filter( 'infinite_scroll_query_args', 'karuna_woocommerce_jetpack_duplicate_products', 100 );
-
 /**
  * Override number of products per page in Jetpack infinite scroll.
  *

+ 1 - 1
karuna/style.css

@@ -4,7 +4,7 @@ Theme URI: http://wordpress.com/themes/karuna/
 Author: Automattic
 Author URI: http://wordpress.com/themes/
 Description: Karuna is a clean business theme designed with health and wellness-focused sites in mind. With bright, bold colors, prominent featured images, and support for customer testimonials, your business' brand will shine with Karuna.
-Version: 1.2.6-wpcom
+Version: 1.2.7-wpcom
 License: GNU General Public License v2 or later
 License URI: http://www.gnu.org/licenses/gpl-2.0.html
 Text Domain: karuna

+ 4 - 0
karuna/woocommerce.css

@@ -678,6 +678,10 @@ ul#shipping_method {
 .infinite-scroll .woocommerce-pagination {
   display: none; }
 
+.infinite-scroll.woocommerce-page .infinite-loader {
+  margin: 1em auto;
+  width: 2.1em; }
+
 /**
  * Onsale
  */

+ 1 - 2
libre-2/inc/woocommerce.php

@@ -132,7 +132,6 @@ function libre_2_woocommerce_related_products_args( $args ) {
 		'posts_per_page' => 3,
 		'columns'        => 3,
 	) );
-
 	return $args;
 }
 add_filter( 'woocommerce_output_related_products_args', 'libre_2_woocommerce_related_products_args' );
@@ -329,4 +328,4 @@ function libre_2_woocommerce_is_shop_page() {
 		$is_shop_page = is_shop();
 	}
 	return $is_shop_page;
-}
+}

+ 0 - 17
lodestar/inc/woocommerce.php

@@ -296,23 +296,6 @@ function lodestar_woocommerce_is_shop_page() {
 	return $is_shop_page;
 }
 
-/**
- * Jetpack infinite scroll duplicates posts where orderby is anything other than modified or date
- * This filter offsets the products returned by however many are displayed per page
- *
- * @link https://github.com/Automattic/jetpack/issues/1135
- * @param  array $args infinite scroll args.
- * @return array       infinite scroll args.
- */
-function lodestar_woocommerce_jetpack_duplicate_products( $args ) {
-	if ( ( isset( $args['post_type'] ) && 'product' === $args['post_type'] ) || ( isset( $args['taxonomy'] ) && 'product_cat' === $args['taxonomy'] ) ) {
-		$args['offset'] = $args['posts_per_page'] * $args['paged'];
-	}
-
- 	return $args;
-}
-add_filter( 'infinite_scroll_query_args', 'lodestar_woocommerce_jetpack_duplicate_products', 100 );
-
 /**
  * Override number of products per page in Jetpack infinite scroll.
  *

+ 1 - 1
lodestar/style.css

@@ -4,7 +4,7 @@ Theme URI: http://theme.wordpress.com/themes/lodestar
 Author: Automattic
 Author URI: https://www.wordpress.com
 Description: Lodestar is a trendy one-page theme designed with startups and small business ventures in mind.
-Version: 1.0.11
+Version: 1.0.12
 License: GNU General Public License v2 or later
 License URI: http://www.gnu.org/licenses/gpl-2.0.html
 Text Domain: lodestar

+ 0 - 1
pique/inc/jetpack.php

@@ -14,7 +14,6 @@ function pique_jetpack_setup() {
 		'render'         => 'pique_infinite_scroll_render',
 		'footer'         => 'tertiary',
 		'footer_widgets' => array( 'sidebar-2', 'sidebar-3', 'sidebar-4' ),
-		'posts_per_page' => 9
 	) );
 
 	// Add theme support for Responsive Videos.

+ 8 - 35
pique/inc/woocommerce.php

@@ -112,7 +112,10 @@ add_filter( 'body_class', 'pique_woocommerce_active_body_class' );
  * @return integer number of products.
  */
 function pique_woocommerce_products_per_page() {
-	return 12;
+	return absint( apply_filters( 'pique_woocommerce_products_per_page', 12 ) );
+}
+if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '3.3', '<' ) ) {
+	add_filter( 'loop_shop_per_page', 'pique_woocommerce_products_per_page' );
 }
 
 // Legacy WooCommerce products per page filter.
@@ -126,7 +129,7 @@ if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '3.3', '<' ) ) {
  * @return integer number of columns.
  */
 function pique_woocommerce_thumbnail_columns() {
-	return 4;
+	return absint( apply_filters( 'pique_woocommerce_product_thumbnail_columns', 4 ) );
 }
 add_filter( 'woocommerce_product_thumbnails_columns', 'pique_woocommerce_thumbnail_columns' );
 
@@ -136,7 +139,7 @@ add_filter( 'woocommerce_product_thumbnails_columns', 'pique_woocommerce_thumbna
  * @return integer products per row.
  */
 function pique_woocommerce_loop_columns() {
-	return 3;
+	return absint( apply_filters( 'pique_woocommerce_loop_columns', 3 ) );
 }
 
 // Legacy WooCommerce columns filter.
@@ -151,12 +154,10 @@ if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '3.3', '<' ) ) {
  * @return array $args related products args.
  */
 function pique_woocommerce_related_products_args( $args ) {
-	$defaults = array(
+	$args = apply_filters( 'radcliffe_2_woocommerce_related_products_args', array(
 		'posts_per_page' => 3,
 		'columns'        => 3,
-	);
-
-	$args = wp_parse_args( $defaults, $args );
+	) );
 
 	return $args;
 }
@@ -242,18 +243,6 @@ if ( ! function_exists( 'pique_woocommerce_wrapper_after' ) ) {
 }
 add_action( 'woocommerce_after_main_content', 'pique_woocommerce_wrapper_after' );
 
-/**
- * Sample implementation of the WooCommerce Mini Cart.
- *
- * You can add the WooCommerce Mini Cart to header.php like so ...
- *
-	<?php
-		if ( function_exists( 'pique_woocommerce_header_cart' ) ) {
-			pique_woocommerce_header_cart();
-		}
-	?>
- */
-
 if ( ! function_exists( 'pique_woocommerce_cart_link_fragment' ) ) {
 	/**
 	 * Cart Fragments.
@@ -411,22 +400,6 @@ function pique_woocommerce_is_shop_page() {
 	return $is_shop_page;
 }
 
-/**
- * Jetpack infinite scroll duplicates posts where orderby is anything other than modified or date
- * This filter offsets the products returned by however many are displayed per page
- *
- * @link https://github.com/Automattic/jetpack/issues/1135
- * @param  array $args infinite scroll args.
- * @return array       infinite scroll args.
- */
-function pique_woocommerce_jetpack_duplicate_products( $args ) {
-	if ( ( isset( $args['post_type'] ) && 'product' === $args['post_type'] ) || ( isset( $args['taxonomy'] ) && 'product_cat' === $args['taxonomy'] ) ) {
-		$args['offset'] = $args['posts_per_page'] * $args['paged'];
-	}
- 	return $args;
-}
-add_filter( 'infinite_scroll_query_args', 'pique_woocommerce_jetpack_duplicate_products', 100 );
-
 /**
  * Override number of products per page in Jetpack infinite scroll.
  *

+ 1 - 1
pique/style.css

@@ -4,7 +4,7 @@ Theme URI: https://wordpress.com/themes/pique/
 Author: Automattic
 Author URI: http://wordpress.com/themes/
 Description: A one-page scrolling theme for small businesses.
-Version: 1.4.4-wpcom
+Version: 1.4.5-wpcom
 License: GNU General Public License v2 or later
 License URI: http://www.gnu.org/licenses/gpl-2.0.html
 Text Domain: pique

+ 4 - 0
pique/woocommerce.css

@@ -379,6 +379,10 @@ ul.products li.product .added_to_cart:hover {
 	display: none;
 }
 
+.infinite-scroll.woocommerce-page #infinite-handle button::before {
+	display: none;
+}
+
 /**
  * Single product
  */

+ 1 - 2
radcliffe-2/inc/jetpack.php

@@ -19,7 +19,7 @@ function radcliffe_2_jetpack_setup() {
 		'container'      => 'main',
 		'render'         => 'radcliffe_2_infinite_scroll_render',
 		'footer'         => 'page',
-		'wrapper'        => false,
+		'wrapper'         => false,
 		'footer_widgets' => array( 'sidebar-1', 'sidebar-2', 'sidebar-3' ),
 	) );
 
@@ -56,7 +56,6 @@ 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();

+ 0 - 17
shoreditch/inc/woocommerce.php

@@ -266,23 +266,6 @@ function shoreditch_woocommerce_is_shop_page() {
 	return $is_shop_page;
 }
 
-/**
- * Jetpack infinite scroll duplicates posts where orderby is anything other than modified or date
- * This filter offsets the products returned by however many are displayed per page
- *
- * @link https://github.com/Automattic/jetpack/issues/1135
- * @param  array $args infinite scroll args.
- * @return array       infinite scroll args.
- */
-function shoreditch_woocommerce_jetpack_duplicate_products( $args ) {
-	if ( ( isset( $args['post_type'] ) && 'product' === $args['post_type'] ) || ( isset( $args['taxonomy'] ) && 'product_cat' === $args['taxonomy'] ) ) {
-		$args['offset'] = $args['posts_per_page'] * $args['paged'];
-	}
-
- 	return $args;
-}
-add_filter( 'infinite_scroll_query_args', 'shoreditch_woocommerce_jetpack_duplicate_products', 100 );
-
 /**
  * Override number of products per page in Jetpack infinite scroll.
  *

+ 1 - 1
shoreditch/style.css

@@ -4,7 +4,7 @@ Theme URI: https://wordpress.com/themes/shoreditch/
 Author: Automattic
 Author URI: https://wordpress.com/themes/
 Description: Shoreditch is a functional and responsive theme perfect for your business’s online presence. Although its main purpose is business, Shoreditch looks great as a personal blog theme too.
-Version: 1.2.3-wpcom
+Version: 1.2.4-wpcom
 License: GNU General Public License v2 or later
 License URI: http://www.gnu.org/licenses/gpl-2.0.html
 Text Domain: shoreditch