Variation Swatches for WooCommerce - Version 1.0.8

Version Description

  • Enhancement - Disable invalid swatches base on select ones.
  • Fix - Can't deactivate plugin without WooCommerce installed.
Download this release

Release Info

Developer themealien
Plugin Icon 128x128 Variation Swatches for WooCommerce
Version 1.0.8
Comparing to
See all releases

Code changes from version 1.0.7 to 1.0.8

assets/css/frontend.css CHANGED
@@ -33,7 +33,12 @@
33
  }
34
 
35
  .tawcvs-swatches .swatch.disabled {
36
- opacity: 0.1;
 
 
 
 
 
37
  }
38
 
39
  .tawcvs-swatches .swatch-color {
@@ -125,4 +130,4 @@
125
  opacity: 1;
126
  visibility: visible;
127
  user-select: auto;
128
- }
33
  }
34
 
35
  .tawcvs-swatches .swatch.disabled {
36
+ cursor: default;
37
+ opacity: 0.1 !important;
38
+ }
39
+
40
+ .tawcvs-swatches .swatch.disabled .swatch__tooltip {
41
+ display: none;
42
  }
43
 
44
  .tawcvs-swatches .swatch-color {
130
  opacity: 1;
131
  visibility: visible;
132
  user-select: auto;
133
+ }
assets/js/frontend.js CHANGED
@@ -2,23 +2,26 @@
2
  'use strict';
3
 
4
  /**
5
- * @TODO Code a function the calculate available combination instead of use WC hooks
6
  */
7
  $.fn.tawcvs_variation_swatches_form = function () {
8
  return this.each( function() {
9
- var $form = $( this ),
10
- clicked = null,
11
- selected = [];
12
 
13
  $form
14
  .addClass( 'swatches-support' )
15
  .on( 'click', '.swatch', function ( e ) {
16
  e.preventDefault();
 
17
  var $el = $( this ),
18
  $select = $el.closest( '.value' ).find( 'select' ),
19
- attribute_name = $select.data( 'attribute_name' ) || $select.attr( 'name' ),
20
  value = $el.data( 'value' );
21
 
 
 
 
 
 
22
  $select.trigger( 'focusin' );
23
 
24
  // Check if this combination is available
@@ -29,17 +32,9 @@
29
  return;
30
  }
31
 
32
- clicked = attribute_name;
33
-
34
- if ( selected.indexOf( attribute_name ) === -1 ) {
35
- selected.push(attribute_name);
36
- }
37
-
38
  if ( $el.hasClass( 'selected' ) ) {
39
  $select.val( '' );
40
  $el.removeClass( 'selected' );
41
-
42
- delete selected[selected.indexOf(attribute_name)];
43
  } else {
44
  $el.addClass( 'selected' ).siblings( '.selected' ).removeClass( 'selected' );
45
  $select.val( value );
@@ -48,8 +43,31 @@
48
  $select.change();
49
  } )
50
  .on( 'click', '.reset_variations', function () {
51
- $( this ).closest( '.variations_form' ).find( '.swatch.selected' ).removeClass( 'selected' );
52
- selected = [];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  } )
54
  .on( 'tawcvs_no_matching_variations', function() {
55
  window.alert( wc_add_to_cart_variation_params.i18n_no_matching_variations_text );
@@ -61,4 +79,4 @@
61
  $( '.variations_form' ).tawcvs_variation_swatches_form();
62
  $( document.body ).trigger( 'tawcvs_initialized' );
63
  } );
64
- })( jQuery );
2
  'use strict';
3
 
4
  /**
5
+ * @TODO Code a function that calculate available combination instead of use WC hooks
6
  */
7
  $.fn.tawcvs_variation_swatches_form = function () {
8
  return this.each( function() {
9
+ var $form = $( this );
 
 
10
 
11
  $form
12
  .addClass( 'swatches-support' )
13
  .on( 'click', '.swatch', function ( e ) {
14
  e.preventDefault();
15
+
16
  var $el = $( this ),
17
  $select = $el.closest( '.value' ).find( 'select' ),
 
18
  value = $el.data( 'value' );
19
 
20
+ if ( $el.hasClass( 'disabled' ) ) {
21
+ return;
22
+ }
23
+
24
+ // For old WC
25
  $select.trigger( 'focusin' );
26
 
27
  // Check if this combination is available
32
  return;
33
  }
34
 
 
 
 
 
 
 
35
  if ( $el.hasClass( 'selected' ) ) {
36
  $select.val( '' );
37
  $el.removeClass( 'selected' );
 
 
38
  } else {
39
  $el.addClass( 'selected' ).siblings( '.selected' ).removeClass( 'selected' );
40
  $select.val( value );
43
  $select.change();
44
  } )
45
  .on( 'click', '.reset_variations', function () {
46
+ $form.find( '.swatch.selected' ).removeClass( 'selected' );
47
+ $form.find( '.swatch.disabled' ).removeClass( 'disabled' );
48
+ } )
49
+ .on( 'woocommerce_update_variation_values', function() {
50
+ $form.find( 'tbody tr' ).each( function() {
51
+ var $variationRow = $( this ),
52
+ options = $variationRow.find( 'select' ).find( 'option' ),
53
+ values = [];
54
+
55
+ options.each( function( index, option ) {
56
+ if ( option.value !== '' ) {
57
+ values.push( option.value );
58
+ }
59
+ } );
60
+
61
+ $variationRow.find( '.swatch' ).each( function() {
62
+ var $swatch = $( this );
63
+
64
+ if ( values.indexOf( $swatch.data( 'value' ) ) > -1 ) {
65
+ $swatch.removeClass( 'disabled' );
66
+ } else {
67
+ $swatch.addClass( 'disabled' );
68
+ }
69
+ } );
70
+ } );
71
  } )
72
  .on( 'tawcvs_no_matching_variations', function() {
73
  window.alert( wc_add_to_cart_variation_params.i18n_no_matching_variations_text );
79
  $( '.variations_form' ).tawcvs_variation_swatches_form();
80
  $( document.body ).trigger( 'tawcvs_initialized' );
81
  } );
82
+ })( jQuery );
readme.txt CHANGED
@@ -2,10 +2,10 @@
2
  Contributors: themealien, coderexco
3
  Tags: woocommerce, product attribute, product color, product size, variation swatches, variable products
4
  Requires at least: 4.5
5
- Tested up to: 5.4
6
- Stable tag: 1.0.7
7
  WC requires at least: 3.2.0
8
- WC tested up to: 4.0.0
9
  License: GPLv2 or later
10
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -77,6 +77,10 @@ Yes, it will work with any theme, but may require some styling to make it match
77
 
78
  == Changelog ==
79
 
 
 
 
 
80
  = 1.0.7 =
81
  * Tweak - Update CSS for active state of swatches, remove the box shadow.
82
  * Fix - Tooltip is not showed on image swatches.
2
  Contributors: themealien, coderexco
3
  Tags: woocommerce, product attribute, product color, product size, variation swatches, variable products
4
  Requires at least: 4.5
5
+ Tested up to: 5.4.1
6
+ Stable tag: 1.0.8
7
  WC requires at least: 3.2.0
8
+ WC tested up to: 4.1.0
9
  License: GPLv2 or later
10
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
11
 
77
 
78
  == Changelog ==
79
 
80
+ = 1.0.8 =
81
+ * Enhancement - Disable invalid swatches base on select ones.
82
+ * Fix - Can't deactivate plugin without WooCommerce installed.
83
+
84
  = 1.0.7 =
85
  * Tweak - Update CSS for active state of swatches, remove the box shadow.
86
  * Fix - Tooltip is not showed on image swatches.
variation-swatches-for-woocommerce.php CHANGED
@@ -3,15 +3,15 @@
3
  * Plugin Name: Variation Swatcher for WooCommerce
4
  * Plugin URI: http://themealien.com/wordpress-plugin/woocommerce-variation-swatches
5
  * Description: An extension of WooCommerce to make variable products be more beauty and friendly to users.
6
- * Version: 1.0.7
7
  * Author: ThemeAlien
8
  * Author URI: http://themealien.com/
9
  * Requires at least: 4.5
10
- * Tested up to: 5.4
11
  * Text Domain: wcvs
12
  * Domain Path: /languages
13
  * WC requires at least: 3.0.0
14
- * WC tested up to: 4.0.0
15
  *
16
  * License: GPLv2 or later
17
  * License URI: https://www.gnu.org/licenses/gpl-2.0.html
@@ -84,6 +84,11 @@ if ( ! function_exists( 'ta_wc_variation_swatches_deactivate' ) ) {
84
  * or just the current site. Multisite only. Default is false.
85
  */
86
  function ta_wc_variation_swatches_deactivate( $network_deactivating ) {
 
 
 
 
 
87
  global $wpdb;
88
 
89
  $blog_ids = array( 1 );
3
  * Plugin Name: Variation Swatcher for WooCommerce
4
  * Plugin URI: http://themealien.com/wordpress-plugin/woocommerce-variation-swatches
5
  * Description: An extension of WooCommerce to make variable products be more beauty and friendly to users.
6
+ * Version: 1.0.8
7
  * Author: ThemeAlien
8
  * Author URI: http://themealien.com/
9
  * Requires at least: 4.5
10
+ * Tested up to: 5.4.1
11
  * Text Domain: wcvs
12
  * Domain Path: /languages
13
  * WC requires at least: 3.0.0
14
+ * WC tested up to: 4.1.0
15
  *
16
  * License: GPLv2 or later
17
  * License URI: https://www.gnu.org/licenses/gpl-2.0.html
84
  * or just the current site. Multisite only. Default is false.
85
  */
86
  function ta_wc_variation_swatches_deactivate( $network_deactivating ) {
87
+ // Early return if WooCommerce is not activated.
88
+ if ( ! class_exists( 'WooCommerce' ) ) {
89
+ return;
90
+ }
91
+
92
  global $wpdb;
93
 
94
  $blog_ids = array( 1 );