WooCommerce Customizer - Version 1.2

Version Description

  • Fixed issues with add to cart button text customizations in WooCommerce 2.1
Download this release

Release Info

Developer maxrice
Plugin Icon WooCommerce Customizer
Version 1.2
Comparing to
See all releases

Code changes from version 1.1.1 to 1.2

Files changed (2) hide show
  1. readme.txt +5 -2
  2. woocommerce-customizer.php +98 -8
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: maxrice, justinstern, skyverge
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=paypal@skyverge.com&item_name=Donation+for+WooCommerce+Customizer
4
  Tags: woocommerce
5
  Requires at least: 3.5
6
- Tested up to: 3.8
7
- Stable tag: 1.1.1
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -53,6 +53,9 @@ Yes! Fork the plugin on [Github](https://github.com/skyverge/woocommerce-customi
53
 
54
  == Changelog ==
55
 
 
 
 
56
  = 1.1.1 =
57
  * WooCommerce 2.1 Compatibility
58
 
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=paypal@skyverge.com&item_name=Donation+for+WooCommerce+Customizer
4
  Tags: woocommerce
5
  Requires at least: 3.5
6
+ Tested up to: 3.8.1
7
+ Stable tag: 1.2
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
53
 
54
  == Changelog ==
55
 
56
+ = 1.2 =
57
+ * Fixed issues with add to cart button text customizations in WooCommerce 2.1
58
+
59
  = 1.1.1 =
60
  * WooCommerce 2.1 Compatibility
61
 
woocommerce-customizer.php CHANGED
@@ -5,7 +5,7 @@
5
  * Description: Customize WooCommerce without code! Easily change add to cart button text and more.
6
  * Author: SkyVerge
7
  * Author URI: http://www.skyverge.com
8
- * Version: 1.1.1
9
  * Text Domain: wc-customizer
10
  * Domain Path: /languages/
11
  *
@@ -27,6 +27,8 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
27
  if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) )
28
  return;
29
 
 
 
30
 
31
  /**
32
  * The WC_Customizer global object
@@ -70,7 +72,7 @@ class WC_Customizer {
70
 
71
 
72
  /** plugin version number */
73
- const VERSION = '1.1.1';
74
 
75
  /** var array the active filters */
76
  public $filters;
@@ -99,6 +101,17 @@ class WC_Customizer {
99
  $this->install();
100
  }
101
 
 
 
 
 
 
 
 
 
 
 
 
102
  // load filter names and values
103
  $this->filters = get_option( 'wc_customizer_active_customizations' );
104
 
@@ -106,10 +119,26 @@ class WC_Customizer {
106
  if ( ! empty( $this->filters ) ) {
107
 
108
  foreach ( $this->filters as $filter_name => $filter_value ) {
109
- add_filter( $filter_name, array( $this, 'customize' ) );
110
- }
111
 
112
- // for use some day, in a galaxy far, far away, when PHP 5.3+ has greater WP adoption
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  // add_filter( $filter_name, function() use ( $filter_value ) { return $filter_value; } );
114
  }
115
  }
@@ -153,13 +182,73 @@ class WC_Customizer {
153
 
154
  $current_filter = current_filter();
155
 
156
- if ( isset( $this->filters[ $current_filter ] ) )
157
  return $this->filters[ $current_filter ];
 
158
 
159
  // no need to return a value passed in, because if a filter is set, it's designed to only return that value
160
  }
161
 
162
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  /** Admin methods ******************************************************/
164
 
165
 
@@ -167,7 +256,7 @@ class WC_Customizer {
167
  * Return the plugin action links. This will only be called if the plugin
168
  * is active.
169
  *
170
- * @since 0.1
171
  * @param array $actions associative array of action names to anchor tags
172
  * @return array associative array of plugin action links
173
  */
@@ -204,8 +293,9 @@ class WC_Customizer {
204
  }
205
 
206
  // upgrade if installed version lower than plugin version
207
- if ( -1 === version_compare( $installed_version, self::VERSION ) )
208
  $this->upgrade( $installed_version );
 
209
  }
210
 
211
 
5
  * Description: Customize WooCommerce without code! Easily change add to cart button text and more.
6
  * Author: SkyVerge
7
  * Author URI: http://www.skyverge.com
8
+ * Version: 1.2
9
  * Text Domain: wc-customizer
10
  * Domain Path: /languages/
11
  *
27
  if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) )
28
  return;
29
 
30
+ // required compatibility class
31
+ require_once( 'includes/class-wc-customizer-compatibility.php' );
32
 
33
  /**
34
  * The WC_Customizer global object
72
 
73
 
74
  /** plugin version number */
75
+ const VERSION = '1.2';
76
 
77
  /** var array the active filters */
78
  public $filters;
101
  $this->install();
102
  }
103
 
104
+ add_action( 'woocommerce_init', array( $this, 'load_customizations' ) );
105
+ }
106
+
107
+
108
+ /**
109
+ * Load customizations after WC is loaded so the version can be checked
110
+ *
111
+ * @since 1.2
112
+ */
113
+ public function load_customizations() {
114
+
115
  // load filter names and values
116
  $this->filters = get_option( 'wc_customizer_active_customizations' );
117
 
119
  if ( ! empty( $this->filters ) ) {
120
 
121
  foreach ( $this->filters as $filter_name => $filter_value ) {
 
 
122
 
123
+ // WC 2.1 changed the add to cart text filter signatures so conditionally add the new filters
124
+ if ( false !== strpos( $filter_name, 'add_to_cart_text' ) && WC_Customizer_Compatibility::is_wc_version_gte_2_1() ) {
125
+
126
+ if ( $filter_name == 'single_add_to_cart_text' ) {
127
+
128
+ add_filter( 'woocommerce_product_single_add_to_cart_text', array( $this, 'customize_single_add_to_cart_text' ) );
129
+
130
+ } else {
131
+
132
+ add_filter( 'woocommerce_product_add_to_cart_text', array( $this, 'customize_add_to_cart_text' ), 10, 2 );
133
+ }
134
+
135
+ } else {
136
+
137
+ add_filter( $filter_name, array( $this, 'customize' ) );
138
+ }
139
+ }
140
+
141
+ // for use some day, in a galaxy far, far away, when WP has greater 5.3 adoption
142
  // add_filter( $filter_name, function() use ( $filter_value ) { return $filter_value; } );
143
  }
144
  }
182
 
183
  $current_filter = current_filter();
184
 
185
+ if ( isset( $this->filters[ $current_filter ] ) ) {
186
  return $this->filters[ $current_filter ];
187
+ }
188
 
189
  // no need to return a value passed in, because if a filter is set, it's designed to only return that value
190
  }
191
 
192
 
193
+ /**
194
+ * Apply the single add to cart button text customization in WC 2.1+
195
+ *
196
+ * The filter signature changed from `single_add_to_cart_text` to `woocommerce_product_single_add_to_cart_text`
197
+ *
198
+ * @since 1.2
199
+ */
200
+ public function customize_single_add_to_cart_text() {
201
+
202
+ return $this->filters['single_add_to_cart_text'];
203
+ }
204
+
205
+
206
+ /**
207
+ * Apply the shop loop add to cart button text customization in WC 2.1+
208
+ *
209
+ * The filter signature changed from `add_to_cart_text|{type}_add_to_cart_text` to `woocommerce_product_add_to_cart_text`
210
+ *
211
+ * This is sort of a hack but prevents a major refactoring and maintains backwards compatibility until WC 2.1+ can
212
+ * be required
213
+ *
214
+ * @since 1.2
215
+ * @param string $text add to cart text
216
+ * @param WC_Product $product product object
217
+ * @return string modified add to cart text
218
+ */
219
+ public function customize_add_to_cart_text( $text, $product ) {
220
+
221
+ // out of stock add to cart text
222
+ if ( isset( $this->filters['out_of_stock_add_to_cart_text'] ) && ! $product->is_in_stock() ) {
223
+
224
+ return $this->filters['out_of_stock_add_to_cart_text'];
225
+ }
226
+
227
+ if ( isset( $this->filters['add_to_cart_text'] ) && $product->is_type( 'simple' ) ) {
228
+
229
+ // simple add to cart text
230
+ return $this->filters['add_to_cart_text'];
231
+
232
+ } elseif ( isset( $this->filters['variable_add_to_cart_text'] ) && $product->is_type( 'variable') ) {
233
+
234
+ // variable add to cart text
235
+ return $this->filters['variable_add_to_cart_text'];
236
+
237
+ } elseif ( isset( $this->filters['grouped_add_to_cart_text'] ) && $product->is_type( 'grouped' ) ) {
238
+
239
+ // grouped add to cart text
240
+ return $this->filters['grouped_add_to_cart_text'];
241
+
242
+ } elseif( isset( $this->filters['external_add_to_cart_text'] ) && $product->is_type( 'external' ) ) {
243
+
244
+ // external add to cart text
245
+ return $this->filters['external_add_to_cart_text'];
246
+ }
247
+
248
+ return $text;
249
+ }
250
+
251
+
252
  /** Admin methods ******************************************************/
253
 
254
 
256
  * Return the plugin action links. This will only be called if the plugin
257
  * is active.
258
  *
259
+ * @since 1.0
260
  * @param array $actions associative array of action names to anchor tags
261
  * @return array associative array of plugin action links
262
  */
293
  }
294
 
295
  // upgrade if installed version lower than plugin version
296
+ if ( -1 === version_compare( $installed_version, self::VERSION ) ) {
297
  $this->upgrade( $installed_version );
298
+ }
299
  }
300
 
301