浏览代码

Libre 2: Fixes Jetpack Infinite Scroll WC issues.

Jeffrey Pearce 7 年之前
父节点
当前提交
2adae49d6b
共有 3 个文件被更改,包括 40 次插入28 次删除
  1. 3 2
      libre-2/inc/jetpack.php
  2. 35 24
      libre-2/inc/woocommerce.php
  3. 2 2
      libre-2/woocommerce.css

+ 3 - 2
libre-2/inc/jetpack.php

@@ -56,8 +56,9 @@ function libre_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( 'template-parts/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( 'template-parts/content', get_post_format() );

+ 35 - 24
libre-2/inc/woocommerce.php

@@ -89,7 +89,10 @@ add_filter( 'body_class', 'libre_2_woocommerce_active_body_class' );
  * @return integer number of products.
  */
 function libre_2_woocommerce_products_per_page() {
-	return 12;
+	return absint( apply_filters( 'libre_2_woocommerce_products_per_page', 12 ) );
+}
+if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '3.3', '<' ) ) {
+	add_filter( 'loop_shop_per_page', 'libre_2_woocommerce_products_per_page' );
 }
 
 // Legacy WooCommerce products per page filter.
@@ -103,7 +106,7 @@ if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '3.3', '<' ) ) {
  * @return integer number of columns.
  */
 function libre_2_woocommerce_thumbnail_columns() {
-	return 4;
+	return absint( apply_filters( 'libre_2_woocommerce_product_thumbnail_columns', 4 ) );
 }
 add_filter( 'woocommerce_product_thumbnails_columns', 'libre_2_woocommerce_thumbnail_columns' );
 
@@ -113,7 +116,7 @@ add_filter( 'woocommerce_product_thumbnails_columns', 'libre_2_woocommerce_thumb
  * @return integer products per row.
  */
 function libre_2_woocommerce_loop_columns() {
-	return 3;
+	return absint( apply_filters( 'libre_2_woocommerce_loop_columns', 3 ) );
 }
 
 // Legacy WooCommerce columns filter.
@@ -128,13 +131,11 @@ if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '3.3', '<' ) ) {
  * @return array $args related products args.
  */
 function libre_2_woocommerce_related_products_args( $args ) {
-	$defaults = array(
+	$args = apply_filters( 'libre_2_woocommerce_related_products_args', array(
 		'posts_per_page' => 3,
 		'columns'        => 3,
-	);
-
-	$args = wp_parse_args( $defaults, $args );
-
+	) );
+	
 	return $args;
 }
 add_filter( 'woocommerce_output_related_products_args', 'libre_2_woocommerce_related_products_args' );
@@ -179,6 +180,32 @@ if ( ! function_exists( 'libre_2_woocommerce_product_columns_wrapper_close' ) )
 }
 add_action( 'woocommerce_after_shop_loop', 'libre_2_woocommerce_product_columns_wrapper_close', 40 );
 
+add_action( 'woocommerce_before_shop_loop', 'libre_2_woocommerce_sorting_wrap', 3 );
+
+if ( ! function_exists( 'libre_2_woocommerce_sorting_wrap' ) ) {
+	/**
+	 * Sorting wrapper
+	 *
+	 * @return  void
+	 */
+	function libre_2_woocommerce_sorting_wrap() {
+		echo '<div class="woocommerce-sorting-wrap">';
+	}
+}
+
+add_action( 'woocommerce_before_shop_loop', 'libre_2_woocommerce_sorting_wrap_close', 30 );
+
+if ( ! function_exists( 'libre_2_woocommerce_sorting_wrap_close' ) ) {
+	/**
+	 * Sorting wrapper close
+	 *
+	 * @return  void
+	 */
+	function libre_2_woocommerce_sorting_wrap_close() {
+		echo '</div><!-- END .sorting-wrap -->';
+	}
+}
+
 /**
  * Remove default WooCommerce wrapper.
  */
@@ -307,22 +334,6 @@ function libre_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 libre_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', 'libre_2_woocommerce_jetpack_duplicate_products', 100 );
-
 /**
  * Override number of products per page in Jetpack infinite scroll.
  *

+ 2 - 2
libre-2/woocommerce.css

@@ -321,8 +321,8 @@ div[class^='columns-']
 	{
 		float: left;
 
-		width: 48%;
-		margin-right: 4%;
+		width: 30%;
+		margin-right: 5%;
 	}
 	ul.products li.product.first
 	{