Browse Source

Button 2: Adds support for the 3.3+ new WC Customizer options

Danny Dudzic 7 years ago
parent
commit
1b67e7ae91
4 changed files with 53 additions and 28 deletions
  1. 3 3
      button-2/inc/jetpack.php
  2. 34 22
      button-2/inc/woocommerce.php
  3. 8 3
      button-2/woocommerce-rtl.css
  4. 8 0
      button-2/woocommerce.css

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

@@ -67,7 +67,7 @@ add_filter( 'infinite_scroll_has_footer_widgets', 'button_2_has_footer_widgets'
  * @since button 1.0
  * @since button 1.0
  */
  */
 function button_2_infinite_scroll_render() {
 function button_2_infinite_scroll_render() {
-	if ( class_exists( 'WooCommerce' ) && ( is_shop() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
+	if ( class_exists( 'WooCommerce' ) && ( button_2_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
 		button_2_woocommerce_product_columns_wrapper();
 		button_2_woocommerce_product_columns_wrapper();
 		woocommerce_product_loop_start();
 		woocommerce_product_loop_start();
 	}
 	}
@@ -77,14 +77,14 @@ function button_2_infinite_scroll_render() {
 
 
 		if ( is_search() ) :
 		if ( is_search() ) :
 			get_template_part( 'components/content', 'search' );
 			get_template_part( 'components/content', 'search' );
-		elseif ( class_exists( 'WooCommerce' ) && ( is_shop() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) :
+		elseif ( class_exists( 'WooCommerce' ) && ( button_2_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) :
 			wc_get_template_part( 'content', 'product' );
 			wc_get_template_part( 'content', 'product' );
 		else :
 		else :
 			get_template_part( 'components/content', get_post_format() );
 			get_template_part( 'components/content', get_post_format() );
 		endif;
 		endif;
 	}
 	}
 
 
-	if ( class_exists( 'WooCommerce' ) && ( is_shop() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
+	if ( class_exists( 'WooCommerce' ) && ( button_2_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
 		woocommerce_product_loop_end();
 		woocommerce_product_loop_end();
 		button_2_woocommerce_product_columns_wrapper_close();
 		button_2_woocommerce_product_columns_wrapper_close();
 	}
 	}

+ 34 - 22
button-2/inc/woocommerce.php

@@ -16,10 +16,18 @@
  * @return void
  * @return void
  */
  */
 function button_2_woocommerce_setup() {
 function button_2_woocommerce_setup() {
-	add_theme_support( 'woocommerce', array(
-		'thumbnail_image_width' => 584,
-		'single_image_width'    => 584,
-	) );
+	add_theme_support( 'woocommerce', apply_filters( 'button_2_woocommerce_args', array(
+		'single_image_width'    => 366,
+		'thumbnail_image_width' => 390,
+		'product_grid'          => array(
+			'default_columns' => 3,
+			'default_rows'    => 4,
+			'min_columns'     => 1,
+			'max_columns'     => 6,
+			'min_rows'        => 2
+		)
+	) ) );
+
 	add_theme_support( 'wc-product-gallery-zoom' );
 	add_theme_support( 'wc-product-gallery-zoom' );
 	add_theme_support( 'wc-product-gallery-lightbox' );
 	add_theme_support( 'wc-product-gallery-lightbox' );
 	add_theme_support( 'wc-product-gallery-slider' );
 	add_theme_support( 'wc-product-gallery-slider' );
@@ -107,7 +115,11 @@ add_filter( 'woocommerce_product_thumbnails_columns', 'button_2_woocommerce_thum
 function button_2_woocommerce_loop_columns() {
 function button_2_woocommerce_loop_columns() {
 	return absint( apply_filters( 'button_2_woocommerce_loop_columns', 3 ) );
 	return absint( apply_filters( 'button_2_woocommerce_loop_columns', 3 ) );
 }
 }
-add_filter( 'loop_shop_columns', 'button_2_woocommerce_loop_columns' );
+
+// Legacy WooCommerce columns filter.
+if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '3.3', '<' ) ) {
+	add_filter( 'loop_shop_columns', 'button_2_woocommerce_loop_columns' );
+}
 
 
 /**
 /**
  * Related Products Args.
  * Related Products Args.
@@ -116,7 +128,7 @@ add_filter( 'loop_shop_columns', 'button_2_woocommerce_loop_columns' );
  * @return array $args related products args.
  * @return array $args related products args.
  */
  */
 function button_2_woocommerce_related_products_args( $args ) {
 function button_2_woocommerce_related_products_args( $args ) {
-	$args = apply_filters( 'radcliffe_2_woocommerce_related_products_args', array(
+	$args = apply_filters( 'button_2_woocommerce_related_products_args', array(
 		'posts_per_page' => 3,
 		'posts_per_page' => 3,
 		'columns'        => 3,
 		'columns'        => 3,
 	) );
 	) );
@@ -132,12 +144,27 @@ if ( ! function_exists( 'button_2_woocommerce_product_columns_wrapper' ) ) {
 	 * @return  void
 	 * @return  void
 	 */
 	 */
 	function button_2_woocommerce_product_columns_wrapper() {
 	function button_2_woocommerce_product_columns_wrapper() {
-		$columns = button_2_woocommerce_loop_columns();
+		$columns = button_2_loop_columns();
 		echo '<div class="columns columns-' . absint( $columns ) . '">';
 		echo '<div class="columns columns-' . absint( $columns ) . '">';
 	}
 	}
 }
 }
 add_action( 'woocommerce_before_shop_loop', 'button_2_woocommerce_product_columns_wrapper', 40 );
 add_action( 'woocommerce_before_shop_loop', 'button_2_woocommerce_product_columns_wrapper', 40 );
 
 
+if ( ! function_exists( 'button_2_loop_columns' ) ) {
+	/**
+	 * Default loop columns on product archives
+	 *
+	 * @return integer products per row
+	 */
+	function button_2_loop_columns() {
+		$columns = 3; // 3 products per row
+		if ( function_exists( 'wc_get_default_products_per_row' ) ) {
+			$columns = wc_get_default_products_per_row();
+		}
+		return apply_filters( 'button_2_loop_columns', $columns );
+	}
+}
+
 if ( ! function_exists( 'button_2_woocommerce_product_columns_wrapper_close' ) ) {
 if ( ! function_exists( 'button_2_woocommerce_product_columns_wrapper_close' ) ) {
 	/**
 	/**
 	 * Product columns wrapper close.
 	 * Product columns wrapper close.
@@ -280,18 +307,3 @@ function button_2_woocommerce_is_shop_page() {
 
 
 	return $is_shop_page;
 	return $is_shop_page;
 }
 }
-
-/**
- * Override number of products per page in Jetpack infinite scroll.
- *
- * @param  array $args infinite scroll args.
- * @return array       infinite scroll args.
- */
-function button_2_woocommerce_jetpack_products_per_page( $args ) {
-	if ( is_array( $args ) && ( button_2_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
-		 $args['posts_per_page'] = button_2_woocommerce_products_per_page();
-	}
-
-	return $args;
-}
-add_filter( 'infinite_scroll_settings', 'button_2_woocommerce_jetpack_products_per_page' );

+ 8 - 3
button-2/woocommerce-rtl.css

@@ -390,9 +390,14 @@ table.cart .product-remove a {
         float: left;
         float: left;
         margin-right: -10px; } }
         margin-right: -10px; } }
 
 
-/**
- * Checkout
- */
+dl.variation {
+  font-size: .875em;
+  margin: .875em 0 0 0; }
+
+dl.variation dd,
+dl.variation p {
+  margin: 0; }
+
 /**
 /**
  * Checkout
  * Checkout
  */
  */

+ 8 - 0
button-2/woocommerce.css

@@ -357,6 +357,14 @@ table.cart .product-remove a {
     text-align: right;
     text-align: right;
     vertical-align: top; }
     vertical-align: top; }
 
 
+dl.variation {
+  font-size: .875em;
+  margin: .875em 0 0 0; }
+
+dl.variation dd,
+dl.variation p {
+  margin: 0; }
+
 @media screen and (min-width: 48em) {
 @media screen and (min-width: 48em) {
   table.cart tr {
   table.cart tr {
     display: table-row;
     display: table-row;