Printful Integration for WooCommerce - Version 1.0.1

Version Description

Minor improvements

=

Download this release

Release Info

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

Code changes from version 1.0 to 1.0.1

Files changed (3) hide show
  1. PrintfulClient.php +1 -3
  2. printful-shipping.php +35 -11
  3. readme.txt +10 -2
PrintfulClient.php CHANGED
@@ -15,7 +15,7 @@ class PrintfulClient {
15
private $lastResponse;
16
17
const API_URL = 'https://api.theprintful.com/';
18
- const USER_AGENT = 'Printful API WooCommerce Library 1.0';
19
20
/**
21
* @param string $key Printful Store API key
@@ -134,8 +134,6 @@ class PrintfulClient {
134
curl_setopt($curl, CURLOPT_USERPWD, $this->key);
135
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
136
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
137
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
138
- curl_setopt($curl, CURLOPT_MAXREDIRS, 3);
139
140
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 20);
141
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
15
private $lastResponse;
16
17
const API_URL = 'https://api.theprintful.com/';
18
+ const USER_AGENT = 'Printful API WooCommerce Library 1.0.1';
19
20
/**
21
* @param string $key Printful Store API key
134
curl_setopt($curl, CURLOPT_USERPWD, $this->key);
135
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
136
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
137
138
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 20);
139
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
printful-shipping.php CHANGED
@@ -3,7 +3,7 @@
3
Plugin Name: Printful Shipping Rates for WooCommerce
4
Plugin URI: https://wordpress.org/plugins/printful-shipping-for-woocommerce/
5
Description: Printful shipping rates
6
- Version: 1.0
7
Author: Idea Bits LLC
8
License: GPL2 http://www.gnu.org/licenses/gpl-2.0.html
9
*/
@@ -27,8 +27,9 @@ function printful_shipping_init()
27
28
class Printful_Shipping extends WC_Shipping_Method
29
{
30
- public $currencyRate = 1;
31
-
32
33
function __construct()
34
{
@@ -43,11 +44,12 @@ function printful_shipping_init()
43
44
$this->enabled = $this->get_option('enabled');
45
$this->title = $this->get_option('title');
46
47
if (get_woocommerce_currency() != 'USD') {
48
- $currencyRate = (float)$this->get_option('rate');
49
- if($currencyRate>0) {
50
- $this->currencyRate = $currencyRate;
51
}
52
}
53
$this->type = 'order';
@@ -76,6 +78,12 @@ function printful_shipping_init()
76
'description'=> 'Your store\'s Printful API key. Create it in the Prinful dashboard',
77
'default' => '',
78
),
79
);
80
$currency = get_woocommerce_currency();
81
if ($currency != 'USD'){ //Require conversion rate
@@ -118,7 +126,7 @@ function printful_shipping_init()
118
try {
119
$printful = new PrintfulClient($this->get_option('printful_key'));
120
} catch( PrintfulException $e) {
121
- wc_add_notice( $e->getMessage(), 'error' );
122
return false;
123
}
124
@@ -131,19 +139,35 @@ function printful_shipping_init()
131
$rateData = array(
132
'id' => $this->id . '_' . $rate['id'],
133
'label' => $rate['name'],
134
- 'cost' => round($rate['rate'] / $this->currencyRate, 2),
135
'taxes' => '',
136
'calc_tax' => 'per_order'
137
);
138
$this->add_rate($rateData);
139
}
140
} catch ( PrintfulException $e) {
141
- if (WP_DEBUG) {
142
- wc_add_notice( $e->getMessage(), 'error' );
143
- }
144
return false;
145
}
146
}
147
}
148
}
149
3
Plugin Name: Printful Shipping Rates for WooCommerce
4
Plugin URI: https://wordpress.org/plugins/printful-shipping-for-woocommerce/
5
Description: Printful shipping rates
6
+ Version: 1.0.1
7
Author: Idea Bits LLC
8
License: GPL2 http://www.gnu.org/licenses/gpl-2.0.html
9
*/
27
28
class Printful_Shipping extends WC_Shipping_Method
29
{
30
+ public $currency_rate = 1;
31
+ public $show_warnings = false;
32
+ private $last_error = false;
33
34
function __construct()
35
{
44
45
$this->enabled = $this->get_option('enabled');
46
$this->title = $this->get_option('title');
47
+ $this->show_warnings = $this->get_option('show_warnings') == 'yes';
48
49
if (get_woocommerce_currency() != 'USD') {
50
+ $currency_rate = (float)$this->get_option('rate');
51
+ if ($currency_rate>0) {
52
+ $this->currency_rate = $currency_rate;
53
}
54
}
55
$this->type = 'order';
78
'description'=> 'Your store\'s Printful API key. Create it in the Prinful dashboard',
79
'default' => '',
80
),
81
+ 'show_warnings' => array(
82
+ 'title' => 'Show Printful warnings',
83
+ 'type' => 'checkbox',
84
+ 'label' => 'Display Printful status messages if rate API request fails',
85
+ 'default' => 'yes'
86
+ ),
87
);
88
$currency = get_woocommerce_currency();
89
if ($currency != 'USD'){ //Require conversion rate
126
try {
127
$printful = new PrintfulClient($this->get_option('printful_key'));
128
} catch( PrintfulException $e) {
129
+ $this->set_error($e);
130
return false;
131
}
132
139
$rateData = array(
140
'id' => $this->id . '_' . $rate['id'],
141
'label' => $rate['name'],
142
+ 'cost' => round($rate['rate'] / $this->currency_rate, 2),
143
'taxes' => '',
144
'calc_tax' => 'per_order'
145
);
146
$this->add_rate($rateData);
147
}
148
} catch ( PrintfulException $e) {
149
+ $this->set_error($e);
150
return false;
151
}
152
}
153
+
154
+ private function set_error($error)
155
+ {
156
+ if ($this->show_warnings){
157
+ $this->last_error = $error;
158
+ add_filter('woocommerce_cart_no_shipping_available_html', array($this, 'show_error'));
159
+ add_filter('woocommerce_no_shipping_available_html', array($this, 'show_error'));
160
+ }
161
+ }
162
+ public function show_error($data)
163
+ {
164
+ $error = $this->last_error;
165
+ $message = $error->getMessage();
166
+ if($error instanceof PrintfulApiException && $error->getCode() == 401){
167
+ $message = 'Invalid API key';
168
+ }
169
+ return '<p>'.$this->title.': '.htmlspecialchars($message).'</p>';
170
+ }
171
}
172
}
173
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: girts_u
3
Tags: woocommerce, printful, shipping, shipping rates, fulfillment, printing, fedex, carriers, checkout
4
Requires at least: 3.8
5
Tested up to: 4.0
6
- Stable tag: 1.0
7
License: GPLv2 or later
8
License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
@@ -38,9 +38,17 @@ Go to https://www.theprintful.com/dashboard/store , select your WooCommerce stor
38
== Upgrade Notice ==
39
40
= 1.0 =
41
- * First release
42
43
== Changelog ==
44
45
= 1.0 =
46
* First release
3
Tags: woocommerce, printful, shipping, shipping rates, fulfillment, printing, fedex, carriers, checkout
4
Requires at least: 3.8
5
Tested up to: 4.0
6
+ Stable tag: 1.0.1
7
License: GPLv2 or later
8
License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
38
== Upgrade Notice ==
39
40
= 1.0 =
41
+ First release
42
+
43
+ = 1.0.1 =
44
+ Minor improvements
45
46
== Changelog ==
47
48
= 1.0 =
49
* First release
50
+
51
+ = 1.0.1 =
52
+ * Removed CURLOPT_FOLLOWLOCATION that caused problems on some hosting environments
53
+ * Added option to display reason status messages if the rate API request has failed
54
+