Printful Integration for WooCommerce - Version 1.2.6

Version Description

Include shipping rates in tax calculation for states that require that

Download this release

Release Info

Developer printful
Plugin Icon 128x128 Printful Integration for WooCommerce
Version 1.2.6
Comparing to
See all releases

Code changes from version 1.2.5 to 1.2.6

includes/class-printful-api-resource.php CHANGED
File without changes
includes/class-printful-integration.php CHANGED
@@ -110,7 +110,7 @@ class Printful_Integration extends WC_Integration
110
  $countries = $this->get_tax_countries();
111
  if(isset($countries[$country][$state]))
112
  {
113
- $key = 'printful_tax_' . $country.'-'.$state.'-'.$city.'-'.$postcode;
114
  $rate = get_transient($key);
115
  if ($rate === false) {
116
  try {
@@ -129,21 +129,25 @@ class Printful_Integration extends WC_Integration
129
 
130
  if(isset($response['rate']))
131
  {
132
- $rate = $response['rate'];
133
  } else {
134
- $rate = 0;
 
 
 
 
135
  }
136
  set_transient($key, $rate, 1800);
137
  }
138
 
139
- if ($rate)
140
  {
141
- $id = $this->get_printful_rate_id($country, $state);
142
  return array(
143
  $id => array(
144
- 'rate' => $rate * 100,
145
  'label' => 'Sales Tax',
146
- 'shipping' => 'no',
147
  'compound' => 'no',
148
  )
149
  );
@@ -174,7 +178,7 @@ class Printful_Integration extends WC_Integration
174
  }
175
  if(!empty($countries))
176
  {
177
- set_transient('printful_tax_countries', $countries, 86400);
178
  }
179
  }
180
  catch(Exception $e)
@@ -189,17 +193,20 @@ class Printful_Integration extends WC_Integration
189
  /**
190
  * Creates dummy tax rate ID to display Printful tax rates in the cart summary.
191
  */
192
- private function get_printful_rate_id($cc, $state)
193
  {
194
  global $wpdb;
195
 
 
 
196
  $states = WC()->countries->get_states($cc);
197
  $tax_title = (isset($states[$state]) ? $states[$state] .' ': '' ). 'Sales Tax';
198
  $id = $wpdb->get_var(
199
  $wpdb->prepare("SELECT tax_rate_id FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_class='printful'
200
- and tax_rate_country = %s AND tax_rate_state = %s LIMIT 1",
201
  '_'.$cc,
202
- $state
 
203
  ));
204
  if(empty($id))
205
  {
@@ -212,7 +219,7 @@ class Printful_Integration extends WC_Integration
212
  'tax_rate_name' => $tax_title,
213
  'tax_rate_priority' => 1,
214
  'tax_rate_compound' => 0,
215
- 'tax_rate_shipping' => 0,
216
  'tax_rate_class' => 'printful'
217
  )
218
  );
110
  $countries = $this->get_tax_countries();
111
  if(isset($countries[$country][$state]))
112
  {
113
+ $key = 'printful_tax_rate_' . $country.'-'.$state.'-'.$city.'-'.$postcode;
114
  $rate = get_transient($key);
115
  if ($rate === false) {
116
  try {
129
 
130
  if(isset($response['rate']))
131
  {
132
+ $rate = $response;
133
  } else {
134
+ $rate = array(
135
+ 'required' => false,
136
+ 'rate' => 0,
137
+ 'shipping_taxable' => false,
138
+ );
139
  }
140
  set_transient($key, $rate, 1800);
141
  }
142
 
143
+ if ($rate['required'])
144
  {
145
+ $id = $this->get_printful_rate_id($country, $state, $rate['shipping_taxable']);
146
  return array(
147
  $id => array(
148
+ 'rate' => $rate['rate'] * 100,
149
  'label' => 'Sales Tax',
150
+ 'shipping' => $rate['shipping_taxable'] ? 'yes' : 'no',
151
  'compound' => 'no',
152
  )
153
  );
178
  }
179
  if(!empty($countries))
180
  {
181
+ set_transient('printful_tax_countries', $countries, 6 * 3600);
182
  }
183
  }
184
  catch(Exception $e)
193
  /**
194
  * Creates dummy tax rate ID to display Printful tax rates in the cart summary.
195
  */
196
+ private function get_printful_rate_id($cc, $state, $includeShipping = false)
197
  {
198
  global $wpdb;
199
 
200
+ $includeShipping = (int)$includeShipping;
201
+
202
  $states = WC()->countries->get_states($cc);
203
  $tax_title = (isset($states[$state]) ? $states[$state] .' ': '' ). 'Sales Tax';
204
  $id = $wpdb->get_var(
205
  $wpdb->prepare("SELECT tax_rate_id FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_class='printful'
206
+ and tax_rate_country = %s AND tax_rate_state = %s AND tax_rate_shipping = %s LIMIT 1",
207
  '_'.$cc,
208
+ $state,
209
+ $includeShipping
210
  ));
211
  if(empty($id))
212
  {
219
  'tax_rate_name' => $tax_title,
220
  'tax_rate_priority' => 1,
221
  'tax_rate_compound' => 0,
222
+ 'tax_rate_shipping' => $includeShipping,
223
  'tax_rate_class' => 'printful'
224
  )
225
  );
includes/class-printful-shipping.php CHANGED
@@ -235,7 +235,7 @@ class Printful_Shipping extends WC_Shipping_Method
235
  $response = $client->post('shipping/rates', $request, array(
236
  'expedited' => true,
237
  ));
238
- //Cache locally, since WC < 2.6 had problems with caching rates form ultiple packages internally
239
  set_transient($key, $response, 1800);
240
  }
241
 
@@ -244,7 +244,6 @@ class Printful_Shipping extends WC_Shipping_Method
244
  'id' => $this->id . '_' . $rate['id'],
245
  'label' => $rate['name'],
246
  'cost' => $rate['rate'],
247
- 'taxes' => false,
248
  'calc_tax' => 'per_order'
249
  );
250
  $this->add_rate($rateData);
235
  $response = $client->post('shipping/rates', $request, array(
236
  'expedited' => true,
237
  ));
238
+ //Cache locally, since WC < 2.6 had problems with caching rates form multiple packages internally
239
  set_transient($key, $response, 1800);
240
  }
241
 
244
  'id' => $this->id . '_' . $rate['id'],
245
  'label' => $rate['name'],
246
  'cost' => $rate['rate'],
 
247
  'calc_tax' => 'per_order'
248
  );
249
  $this->add_rate($rateData);
printful-shipping.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Printful Integration for WooCommerce
4
  Plugin URI: https://wordpress.org/plugins/printful-shipping-for-woocommerce/
5
  Description: Calculate correct shipping and tax rates for your Printful-Woocommerce integration.
6
- Version: 1.2.5
7
  Author: Printful
8
  Author URI: http://www.theprintful.com
9
  License: GPL2 http://www.gnu.org/licenses/gpl-2.0.html
@@ -16,7 +16,7 @@ new Printful_Base();
16
 
17
  class Printful_Base {
18
 
19
- const VERSION = '1.2.5';
20
 
21
  /**
22
  * Construct the plugin.
3
  Plugin Name: Printful Integration for WooCommerce
4
  Plugin URI: https://wordpress.org/plugins/printful-shipping-for-woocommerce/
5
  Description: Calculate correct shipping and tax rates for your Printful-Woocommerce integration.
6
+ Version: 1.2.6
7
  Author: Printful
8
  Author URI: http://www.theprintful.com
9
  License: GPL2 http://www.gnu.org/licenses/gpl-2.0.html
16
 
17
  class Printful_Base {
18
 
19
+ const VERSION = '1.2.6';
20
 
21
  /**
22
  * Construct the plugin.
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: girts_u
3
  Tags: woocommerce, printful, drop shipping, shipping, shipping rates, fulfillment, printing, fedex, carriers, checkout, t-shirts
4
  Requires at least: 3.8
5
- Tested up to: 4.5.2
6
- Stable tag: 1.2.5
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -40,6 +40,9 @@ Go to https://www.theprintful.com/dashboard/store , select your WooCommerce stor
40
  3. Shipping rate selection
41
 
42
  == Upgrade Notice ==
 
 
 
43
 
44
  = 1.2.5 =
45
  Added option to allow Woocommerce default rates together with Printful rates for Printful products
@@ -78,6 +81,9 @@ Minor improvements
78
  First release
79
 
80
  == Changelog ==
 
 
 
81
 
82
  = 1.2.5 =
83
  * Added option to allow Woocommerce default rates together with Printful rates for Printful products
2
  Contributors: girts_u
3
  Tags: woocommerce, printful, drop shipping, shipping, shipping rates, fulfillment, printing, fedex, carriers, checkout, t-shirts
4
  Requires at least: 3.8
5
+ Tested up to: 4.7
6
+ Stable tag: 1.2.6
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
40
  3. Shipping rate selection
41
 
42
  == Upgrade Notice ==
43
+
44
+ = 1.2.6 =
45
+ Include shipping rates in tax calculation for states that require that
46
 
47
  = 1.2.5 =
48
  Added option to allow Woocommerce default rates together with Printful rates for Printful products
81
  First release
82
 
83
  == Changelog ==
84
+
85
+ = 1.2.6 =
86
+ * Include shipping rates in tax calculation for states that require that
87
 
88
  = 1.2.5 =
89
  * Added option to allow Woocommerce default rates together with Printful rates for Printful products