浏览代码

Dara: Fixes Jetpack Infinite Scroll on WooCommerce pages

Danny Dudzic 7 年之前
父节点
当前提交
ae35fd288d
共有 5 个文件被更改,包括 68 次插入79 次删除
  1. 3 3
      dara/inc/jetpack.php
  2. 2 39
      dara/inc/woocommerce.php
  3. 1 1
      dara/style.css
  4. 29 17
      dara/woocommerce-rtl.css
  5. 33 19
      dara/woocommerce.css

+ 3 - 3
dara/inc/jetpack.php

@@ -89,7 +89,7 @@ if ( function_exists( 'jetpack_is_mobile' ) && class_exists( 'Jetpack_User_Agent
  * Custom render function for Infinite Scroll.
  */
 function dara_infinite_scroll_render() {
-	if ( class_exists( 'WooCommerce' ) && ( is_shop() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
+	if ( class_exists( 'WooCommerce' ) && ( dara_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
 		dara_woocommerce_product_columns_wrapper();
 		woocommerce_product_loop_start();
 	}
@@ -100,14 +100,14 @@ function dara_infinite_scroll_render() {
 			get_template_part( 'components/post/content', 'search' );
 		elseif ( is_post_type_archive( 'jetpack-testimonial' ) ) :
 			get_template_part( 'components/testimonials/content', 'testimonial' );
-		elseif ( class_exists( 'WooCommerce' ) && ( is_shop() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) :
+		elseif ( class_exists( 'WooCommerce' ) && ( dara_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) :
 			wc_get_template_part( 'content', 'product' );
 		else :
 			get_template_part( 'components/post/content', get_post_format() );
 		endif;
 	}
 
-	if ( class_exists( 'WooCommerce' ) && ( is_shop() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
+	if ( class_exists( 'WooCommerce' ) && ( dara_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
 		woocommerce_product_loop_end();
 		dara_woocommerce_product_columns_wrapper_close();
 	}

+ 2 - 39
dara/inc/woocommerce.php

@@ -16,7 +16,6 @@
  * @return void
  */
 function dara_woocommerce_setup() {
-	// Declare WooCommerce support.
 	add_theme_support( 'woocommerce', apply_filters( 'dara_woocommerce_args', array(
 		'single_image_width'    => 624,
 		'thumbnail_image_width' => 300,
@@ -97,8 +96,6 @@ add_filter( 'body_class', 'dara_woocommerce_active_body_class' );
 function dara_woocommerce_products_per_page() {
 	return 12;
 }
-
-// Legacy WooCommerce products per page filter.
 if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '3.3', '<' ) ) {
 	add_filter( 'loop_shop_per_page', 'dara_woocommerce_products_per_page' );
 }
@@ -109,7 +106,7 @@ if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '3.3', '<' ) ) {
  * @return integer number of columns.
  */
 function dara_woocommerce_thumbnail_columns() {
-	return 4;
+	return absint( apply_filters( 'dara_woocommerce_product_thumbnail_columns', 4 ) );
 }
 add_filter( 'woocommerce_product_thumbnails_columns', 'dara_woocommerce_thumbnail_columns' );
 
@@ -119,7 +116,7 @@ add_filter( 'woocommerce_product_thumbnails_columns', 'dara_woocommerce_thumbnai
  * @return integer products per row.
  */
 function dara_woocommerce_loop_columns() {
-	return 4;
+	return absint( apply_filters( 'dara_woocommerce_loop_columns', 4 ) );
 }
 
 // Legacy WooCommerce columns filter.
@@ -166,11 +163,9 @@ if ( ! function_exists( 'dara_loop_columns' ) ) {
 	 */
 	function dara_loop_columns() {
 		$columns = 4; // 4 products per row
-
 		if ( function_exists( 'wc_get_default_products_per_row' ) ) {
 			$columns = wc_get_default_products_per_row();
 		}
-
 		return apply_filters( 'dara_loop_columns', $columns );
 	}
 }
@@ -333,35 +328,3 @@ function dara_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 dara_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', 'dara_woocommerce_jetpack_duplicate_products', 100 );
-
-/**
- * Override number of products per page in Jetpack infinite scroll.
- *
- * @param  array $args infinite scroll args.
- * @return array       infinite scroll args.
- */
-function dara_woocommerce_jetpack_products_per_page( $args ) {
-	if ( is_array( $args ) && ( dara_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
-		 $args['posts_per_page'] = dara_woocommerce_products_per_page();
-	}
-
-	return $args;
-}
-add_filter( 'infinite_scroll_settings', 'dara_woocommerce_jetpack_products_per_page' );

+ 1 - 1
dara/style.css

@@ -4,7 +4,7 @@ Theme URI: http://wordpress.com/themes/dara/
 Author: Automattic
 Author URI: http://wordpress.com/themes/
 Description: With bold featured images and bright, cheerful colors, Dara is ready to get to work for your business.
-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: dara

+ 29 - 17
dara/woocommerce-rtl.css

@@ -614,6 +614,8 @@ ul.products li.product .woocommerce-loop-category__title {
 }
 
 ul.products li.product a {
+  display: block;
+  max-width: 300px;
   text-decoration: none;
 }
 
@@ -634,6 +636,7 @@ ul.products li.product .star-rating {
 }
 
 ul.products li.product .button {
+  display: inline-block;
   margin-top: 1em;
   max-width: 100%;
   white-space: normal;
@@ -1306,6 +1309,7 @@ table.woocommerce-MyAccount-downloads th .woocommerce-MyAccount-downloads-file::
 }
 
 td.product-name dl.variation, td.product-name .wc-item-meta {
+  font-size: .875em;
   list-style: none outside;
 }
 
@@ -1403,6 +1407,7 @@ ul.cart_list li dl dd,
 ul.product_list_widget li dl dt,
 ul.product_list_widget li dl dd {
   display: inline-block;
+  font-size: .875em;
   float: right;
   margin-bottom: 1em;
 }
@@ -1417,7 +1422,8 @@ ul.product_list_widget li dl dt {
 
 ul.cart_list li dl dd,
 ul.product_list_widget li dl dd {
-  padding: 0 0 0.25em;
+  padding: 0;
+  margin: 0;
 }
 
 ul.cart_list li dl dd p:last-child,
@@ -2776,8 +2782,8 @@ ul.order_details li:last-of-type {
     display: inline-block;
   }
   /**
-	 * Header cart
-	 */
+   * Header cart
+   */
   .site-header-cart li:first-child:before {
     color: rgba(0, 0, 0, 0.15);
     content: " \2022";
@@ -3174,7 +3180,6 @@ form .form-row-last {
 
 form .form-row-first {
   float: right;
-		float: right;
 }
 
 form .form-row-last {
@@ -3233,7 +3238,7 @@ form .form-row-wide {
     display: block;
   }
   .woocommerce-account .woocommerce-MyAccount-navigation ul {
-	margin-bottom: 1em;
+    margin-bottom: 1em;
     margin-right: 0;
   }
   .woocommerce-account .woocommerce-MyAccount-navigation ul li {
@@ -3325,16 +3330,16 @@ form .form-row-wide {
     margin: 0.125em 0 0.125em 0.25em;
   }
   /**
-	 * General layout
-	 */
+   * General layout
+   */
   .col2-set .col-1,
   .col2-set .col-2 {
     float: none;
     width: 100%;
   }
   /**
-	 * Products
-	 */
+   * Products
+   */
   .woocommerce-page ul.products li.product, .woocommerce-page[class*='columns-'] ul.products li.product {
     width: 48%;
     float: right;
@@ -3346,8 +3351,8 @@ form .form-row-wide {
     clear: none !important;
   }
   /**
-	 * Product Details
-	 */
+   * Product Details
+   */
   div.product div.images,
   div.product div.summary,
   #content div.product div.images,
@@ -3356,8 +3361,8 @@ form .form-row-wide {
     width: 100%;
   }
   /**
-	 * Cart
-	 */
+   * Cart
+   */
   table.cart .product-thumbnail,
   #content table.cart .product-thumbnail {
     display: none;
@@ -3409,9 +3414,16 @@ form .form-row-wide {
     float: none;
     text-align: right;
   }
+
+  dl.variation dd,
+  dl.variation p {
+    margin: 0;
+    padding: 0;
+  }
+
   /**
-	 * Checkout
-	 */
+   * Checkout
+   */
   .woocommerce-checkout form.login .form-row {
     width: 100%;
     float: none;
@@ -3427,8 +3439,8 @@ form .form-row-wide {
     margin-bottom: 1em;
   }
   /**
-	 * Account
-	 */
+   * Account
+   */
   .lost_reset_password .form-row-first,
   .lost_reset_password .form-row-last {
     width: 100%;

+ 33 - 19
dara/woocommerce.css

@@ -614,7 +614,9 @@ ul.products li.product .woocommerce-loop-category__title {
 }
 
 ul.products li.product a {
+  display: block;
   text-decoration: none;
+  max-width: 300px;
 }
 
 ul.products li.product a img {
@@ -634,6 +636,7 @@ ul.products li.product .star-rating {
 }
 
 ul.products li.product .button {
+  display: inline-block;
   margin-top: 1em;
   max-width: 100%;
   white-space: normal;
@@ -1306,6 +1309,7 @@ table.woocommerce-MyAccount-downloads th .woocommerce-MyAccount-downloads-file::
 }
 
 td.product-name dl.variation, td.product-name .wc-item-meta {
+  font-size: .875em;
   list-style: none outside;
 }
 
@@ -1403,6 +1407,7 @@ ul.cart_list li dl dd,
 ul.product_list_widget li dl dt,
 ul.product_list_widget li dl dd {
   display: inline-block;
+  font-size: .875em;
   float: left;
   margin-bottom: 1em;
 }
@@ -1417,7 +1422,8 @@ ul.product_list_widget li dl dt {
 
 ul.cart_list li dl dd,
 ul.product_list_widget li dl dd {
-  padding: 0 0 0.25em;
+  padding: 0;
+  margin: 0;
 }
 
 ul.cart_list li dl dd p:last-child,
@@ -2777,8 +2783,8 @@ ul.order_details li:last-of-type {
     display: inline-block;
   }
   /**
-	 * Header cart
-	 */
+  * Header cart
+  */
   .site-header-cart li:first-child:before {
     color: rgba(0, 0, 0, 0.15);
     content: " \2022";
@@ -3175,9 +3181,10 @@ form .form-row-last {
 
 form .form-row-first {
   float: left;
-  /*rtl:raw:
-		float: right;
-		*/
+/*
+  rtl:raw:
+  float: right;
+*/
 }
 
 form .form-row-last {
@@ -3236,7 +3243,7 @@ form .form-row-wide {
     display: block;
   }
   .woocommerce-account .woocommerce-MyAccount-navigation ul {
-	margin-bottom: 1em;
+    margin-bottom: 1em;
     margin-left: 0;
   }
   .woocommerce-account .woocommerce-MyAccount-navigation ul li {
@@ -3328,16 +3335,16 @@ form .form-row-wide {
     margin: 0.125em 0.25em 0.125em 0;
   }
   /**
-	 * General layout
-	 */
+   * General layout
+   */
   .col2-set .col-1,
   .col2-set .col-2 {
     float: none;
     width: 100%;
   }
   /**
-	 * Products
-	 */
+   * Products
+   */
   .woocommerce-page ul.products li.product, .woocommerce-page[class*='columns-'] ul.products li.product {
     width: 48%;
     float: left;
@@ -3349,8 +3356,8 @@ form .form-row-wide {
     clear: none !important;
   }
   /**
-	 * Product Details
-	 */
+   * Product Details
+   */
   div.product div.images,
   div.product div.summary,
   #content div.product div.images,
@@ -3359,8 +3366,8 @@ form .form-row-wide {
     width: 100%;
   }
   /**
-	 * Cart
-	 */
+   * Cart
+   */
   table.cart .product-thumbnail,
   #content table.cart .product-thumbnail {
     display: none;
@@ -3412,9 +3419,16 @@ form .form-row-wide {
     float: none;
     text-align: left;
   }
+
+  dl.variation dd,
+  dl.variation p {
+    margin: 0;
+    padding: 0;
+  }
+
   /**
-	 * Checkout
-	 */
+   * Checkout
+   */
   .woocommerce-checkout form.login .form-row {
     width: 100%;
     float: none;
@@ -3430,8 +3444,8 @@ form .form-row-wide {
     margin-bottom: 1em;
   }
   /**
-	 * Account
-	 */
+   * Account
+   */
   .lost_reset_password .form-row-first,
   .lost_reset_password .form-row-last {
     width: 100%;