PluginProbe ʕ •ᴥ•ʔ
Weight Based Shipping Table Rate for WooCommerce – Flexible Shipping / 6.10.0
Weight Based Shipping Table Rate for WooCommerce – Flexible Shipping v6.10.0
6.12.1 6.12.0 6.11.0 6.10.0 6.9.1 6.9.0 6.8.1 6.8.0 6.7.4 6.7.3 6.7.2 6.7.0 4.21.7 4.22.0 4.22.1 4.23.0 4.23.1 4.23.2 4.23.3 4.24.0 4.24.1 4.24.10 4.24.11 4.24.12 4.24.13 4.24.14 4.24.15 4.24.16 4.24.17 4.24.18 4.24.19 4.24.2 4.24.4 4.24.6 4.24.7 4.24.8 4.24.9 4.25.0 4.25.1 4.25.2 4.25.4 4.25.5 4.25.6 4.25.7 4.25.8 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 4.8.0 4.8.1 4.8.3 4.8.4 4.8.5 4.9.0 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.0.9 5.1.0 5.1.1 5.1.2 5.1.3 5.2.0 5.3.0 5.3.1 5.3.3 5.3.4 5.3.5 6.0.0 6.1.0 6.1.1 6.1.2 6.2.0 6.2.1 6.2.2 6.2.3 6.2.4 6.3.0 trunk 6.4.0 1.4 6.4.1 1.4.1 6.4.2 1.5 6.4.3 1.6 6.4.5 1.6.1 6.5.0 1.6.2 6.5.1 1.7 6.5.2 1.8 6.5.3 1.9 6.5.4 1.9.1 6.5.5 1.9.10 6.5.6 1.9.11 6.5.7 1.9.12 6.5.8 1.9.2 6.6.0 1.9.3 6.6.1 1.9.4 6.6.2 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0 2.0.1 2.1 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.6 3.0.7 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.10.0 3.11.0 3.11.1 3.11.2 3.11.3 3.11.4 3.12.0 3.13.0 3.14.0 3.14.1 3.14.2 3.14.3 3.14.4 3.15.0 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.2.0 3.3.1 3.3.10 3.3.11 3.3.12 3.3.13 3.3.14 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.8.0 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.9 4.0.0 4.0.1 4.0.10 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.11.0 4.11.1 4.11.2 4.11.3 4.11.4 4.11.5 4.11.6 4.11.7 4.11.8 4.11.9 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.14.0 4.14.1 4.14.2 4.15.0 4.16.0 4.16.1 4.16.2 4.17.0 4.18.0 4.18.1 4.18.2 4.18.3 4.18.4 4.18.5 4.18.6 4.19.0 4.19.1 4.2.0 4.20.0 4.20.1 4.20.2 4.20.3 4.21.0 4.21.1 4.21.2 4.21.3 4.21.4 4.21.5
flexible-shipping / src / WPDesk / FS / TableRate / ContextualInfo / Creator.php
flexible-shipping / src / WPDesk / FS / TableRate / ContextualInfo Last commit date
Creator.php 1 month ago
Creator.php
407 lines
1 <?php
2 /**
3 * Contextual info creator.
4 *
5 * @package Contextual Info
6 */
7
8 namespace WPDesk\FS\TableRate\ContextualInfo;
9
10 use Flexible_Shipping_Contextual_Info;
11 use FSVendor\WPDesk\PluginBuilder\Plugin\HookableCollection;
12 use FSVendor\WPDesk\PluginBuilder\Plugin\HookableParent;
13
14 /**
15 * Can create contextual info.
16 */
17 class Creator implements HookableCollection {
18
19 use HookableParent;
20
21 const METHOD_TITLE_ELEMENT = 'woocommerce_flexible_shipping_method_title';
22 const METHOD_TITLE_AND_METHOD_DESCRIPTION_ELEMENTS = 'woocommerce_flexible_shipping_method_title,woocommerce_flexible_shipping_method_description';
23
24 /**
25 * @var string
26 */
27 private $base_location_country;
28
29 /**
30 * Flexible_Shipping_Contextual_Info_Creator constructor.
31 *
32 * @param string $base_location_country .
33 */
34 public function __construct( $base_location_country ) {
35 $this->base_location_country = $base_location_country;
36 }
37
38 /**
39 * Hooks.
40 */
41 public function hooks() {
42 $this->hooks_on_hookable_objects();
43 }
44
45 /**
46 * Create contextual info.
47 */
48 public function create_contextual_info() {
49 $other_phrases_not_in = [];
50
51 $phrases_in = $this->get_dhl_express_phrases();
52 $this->create_dhl_express_contextual_info( $phrases_in );
53 $other_phrases_not_in = $this->merge_phrases( $other_phrases_not_in, $phrases_in );
54
55 $phrases_in = [ 'fedex' ];
56 $this->create_fedex_contextual_info( $phrases_in );
57 $other_phrases_not_in = $this->merge_phrases( $other_phrases_not_in, $phrases_in );
58
59 $phrases_in = [ 'ups' ];
60 $this->create_ups_contextual_info( $phrases_in );
61 $other_phrases_not_in = $this->merge_phrases( $other_phrases_not_in, $phrases_in );
62
63 if ( $this->is_base_location_country_pl() ) {
64 $phrases_in = [ 'dpd' ];
65 $this->create_dpd_contextual_info( $phrases_in );
66 $other_phrases_not_in = $this->merge_phrases( $other_phrases_not_in, $phrases_in );
67
68 $phrases_in = [ 'List', 'poczta polska', 'pocztex', 'polecony', 'poczt', 'enadawca' ];
69 $this->create_enadawca_contextual_info( $phrases_in );
70 $other_phrases_not_in = $this->merge_phrases( $other_phrases_not_in, $phrases_in );
71
72 $phrases_in = [ 'dhl', 'parcel' ];
73 $this->create_dhl_contextual_info( $phrases_in );
74 $other_phrases_not_in = $this->merge_phrases( $other_phrases_not_in, $phrases_in );
75
76 $phrases_in = [ 'ruch', 'kiosk', 'orlen' ];
77 $this->create_pwr_contextual_info( $phrases_in );
78 $other_phrases_not_in = $this->merge_phrases( $other_phrases_not_in, $phrases_in );
79
80 $phrases_in = [ 'paczkomat', 'paczka w weekend', 'inpost' ];
81 $this->create_inpost_contextual_info( $phrases_in );
82 $other_phrases_not_in = $this->merge_phrases( $other_phrases_not_in, $phrases_in );
83 } elseif ( $this->is_base_location_country_gb() ) {
84 $phrases_in = [ 'air', 'dpd' ];
85 $this->create_dpd_uk_contextual_info( $phrases_in );
86 $other_phrases_not_in = $this->merge_phrases( $other_phrases_not_in, $phrases_in );
87 } elseif ( $this->is_base_location_country_us() ) {
88 $phrases_in = [ 'usps' ];
89 $this->create_usps_contextual_info( $phrases_in );
90 $other_phrases_not_in = $this->merge_phrases( $other_phrases_not_in, $phrases_in );
91 }
92
93 $this->create_default_contextual_info( $other_phrases_not_in );
94 }
95
96 /**
97 * @return array
98 */
99 private function get_dhl_express_phrases() {
100 if ( $this->is_base_location_country_pl() ) {
101 return [ 'dhl express' ];
102 } else {
103 return [ 'dhl', 'dhl express' ];
104 }
105 }
106
107 /**
108 * @return bool
109 */
110 private function is_base_location_country_pl() {
111 return 'PL' === $this->base_location_country;
112 }
113
114 /**
115 * @return bool
116 */
117 private function is_base_location_country_us() {
118 return stripos( $this->base_location_country, 'US' ) !== false;
119 }
120
121 /**
122 * @return bool
123 */
124 private function is_base_location_country_gb() {
125 return 'GB' === $this->base_location_country;
126 }
127
128 /**
129 * @param array $phrases1 .
130 * @param array $phrases2 .
131 *
132 * @return array
133 */
134 private function merge_phrases( array $phrases1, array $phrases2 ) {
135 return array_merge( $phrases1, $phrases2 );
136 }
137
138 /**
139 * @param array $phrases_in .
140 */
141 private function create_dhl_express_contextual_info( array $phrases_in ) {
142 if ( ! defined( 'FLEXIBLE_SHIPPING_DHL_EXPRESS_VERSION' ) && ! defined( 'FLEXIBLE_SHIPPING_DHL_EXPRESS_PRO_VERSION' ) ) {
143 $this->add_hookable(
144 new Flexible_Shipping_Contextual_Info(
145 self::METHOD_TITLE_AND_METHOD_DESCRIPTION_ELEMENTS,
146 'dhl_express',
147 $phrases_in,
148 sprintf(
149 // Translators: link.
150 __( 'Want to show your customers the DHL Express live rates? %1$sCheck our DHL Express plugin%2$s', 'flexible-shipping' ),
151 '<a class="oct-btn-more" href="https://octol.io/fs-cross-dhl-express" target="_blank">',
152 '</a>'
153 )
154 )
155 );
156 }
157 }
158
159 /**
160 * @param array $phrases_in .
161 */
162 private function create_fedex_contextual_info( array $phrases_in ) {
163 if ( ! defined( 'FLEXIBLE_SHIPPING_FEDEX_VERSION' ) && ! defined( 'FLEXIBLE_SHIPPING_FEDEX_PRO_VERSION' ) ) {
164 $target_url = $this->is_base_location_country_pl()
165 ? 'https://octol.io/fs-cross-fedex-pl'
166 : 'https://octol.io/fs-cross-fedex';
167 $this->add_hookable(
168 new Flexible_Shipping_Contextual_Info(
169 self::METHOD_TITLE_AND_METHOD_DESCRIPTION_ELEMENTS,
170 'fedex',
171 $phrases_in,
172 sprintf(
173 // Translators: link.
174 __( 'Want to show your customers the FedEx live rates? %1$sCheck our FedEx plugin%2$s', 'flexible-shipping' ),
175 '<a class="oct-btn-more" href="' . $target_url . '" target="_blank">',
176 '</a>'
177 )
178 )
179 );
180 }
181 }
182
183 /**
184 * @param array $phrases_in .
185 */
186 private function create_ups_contextual_info( array $phrases_in ) {
187 if ( ! defined( 'WOOCOMMERCE_UPS_LABELS_VERSION' ) ) {
188 $target_url = get_user_locale() === 'pl_PL'
189 ? 'https://octol.io/fs-cross-ups-labels-pl'
190 : 'https://octol.io/fs-cross-ups-labels';
191 $this->add_hookable(
192 new Flexible_Shipping_Contextual_Info(
193 self::METHOD_TITLE_AND_METHOD_DESCRIPTION_ELEMENTS,
194 'ups',
195 $phrases_in,
196 sprintf(
197 // Translators: link.
198 __( 'Sending your products with UPS? Create the shipments and generate shipping labels directly from your shop using our %1$sUPS Labels%2$s', 'flexible-shipping' ),
199 '<a class="oct-btn-more" href="' . $target_url . '" target="_blank">',
200 '</a>'
201 )
202 )
203 );
204 }
205 }
206
207 /**
208 * @param array $phrases_in .
209 */
210 private function create_usps_contextual_info( array $phrases_in ) {
211 if ( ! defined( 'FLEXIBLE_SHIPPING_USPS_PRO_VERSION' ) ) {
212 $target_url = 'https://octol.io/fs-cross-usps';
213
214 $this->add_hookable(
215 new Flexible_Shipping_Contextual_Info(
216 self::METHOD_TITLE_AND_METHOD_DESCRIPTION_ELEMENTS,
217 'usps',
218 $phrases_in,
219 sprintf(
220 // Translators: link.
221 __( 'Want to show your customers the USPS live rates? %1$sCheck our USPS plugin%2$s', 'flexible-shipping' ),
222 '<a class="oct-btn-more" href="' . esc_url( $target_url ) . '" target="_blank">',
223 '</a>'
224 )
225 )
226 );
227 }
228 }
229
230 /**
231 * @param array $phrases_in .
232 */
233 private function create_dpd_contextual_info( array $phrases_in ) {
234 if ( ! defined( 'WOOCOMMERCE_DPD_VERSION' ) ) {
235 $this->add_hookable(
236 new Flexible_Shipping_Contextual_Info(
237 self::METHOD_TITLE_AND_METHOD_DESCRIPTION_ELEMENTS,
238 'dpd',
239 $phrases_in,
240 sprintf(
241 // Translators: link.
242 __( 'Sending your products via DPD? Create the shipments and generate shipping labels directly from your shop using our %1$sDPD integration%2$s', 'flexible-shipping' ),
243 '<a class="oct-btn-more" href="https://octol.io/fs-context-cross-dpd-pl" target="_blank">',
244 '</a>'
245 )
246 )
247 );
248 }
249 }
250
251 /**
252 * @param array $phrases_in .
253 */
254 private function create_enadawca_contextual_info( array $phrases_in ) {
255 if ( ! defined( 'WOOCOMMERCE_ENADAWCA_VERSION' ) ) {
256 $this->add_hookable(
257 new Flexible_Shipping_Contextual_Info(
258 self::METHOD_TITLE_AND_METHOD_DESCRIPTION_ELEMENTS,
259 'enadawca',
260 $phrases_in,
261 sprintf(
262 // Translators: link.
263 __( 'Sending your products via Poczta Polska? Create the shipments and generate shipping labels directly from your shop using our %1$sPoczta Polska eNadawca integration%2$s', 'flexible-shipping' ),
264 '<a class="oct-btn-more" href="https://octol.io/fs-context-cross-enadawca-pl" target="_blank">',
265 '</a>'
266 )
267 )
268 );
269 }
270 }
271
272 /**
273 * @param array $phrases_in .
274 */
275 private function create_dhl_contextual_info( array $phrases_in ) {
276 if ( ! defined( 'WOOCOMMERCE_DHL_VERSION' ) ) {
277 $this->add_hookable(
278 new Flexible_Shipping_Contextual_Info(
279 self::METHOD_TITLE_AND_METHOD_DESCRIPTION_ELEMENTS,
280 'dhl',
281 $phrases_in,
282 sprintf(
283 // Translators: link.
284 __( 'Sending your products via DHL? Create the shipments and generate shipping labels directly from your shop using our %1$sDHL integration%2$s', 'flexible-shipping' ),
285 '<a class="oct-btn-more" href="https://octol.io/fs-context-cross-dhl-pl" target="_blank">',
286 '</a>'
287 )
288 )
289 );
290 }
291 }
292
293 /**
294 * @param array $phrases_in .
295 */
296 private function create_pwr_contextual_info( array $phrases_in ) {
297 if ( ! defined( 'WOOCOMMERCE_PACZKA_W_RUCHU_VERSION' ) ) {
298 $this->add_hookable(
299 new Flexible_Shipping_Contextual_Info(
300 self::METHOD_TITLE_AND_METHOD_DESCRIPTION_ELEMENTS,
301 'pwr',
302 $phrases_in,
303 sprintf(
304 // Translators: link.
305 __( 'Sending your products via Orlen Paczka? Create the shipments and generate shipping labels directly from your shop using our %1$sOrlen Paczka integration%2$s', 'flexible-shipping' ),
306 '<a class="oct-btn-more" href="https://octol.io/fs-context-cross-op-pl" target="_blank">',
307 '</a>'
308 )
309 )
310 );
311 }
312 }
313
314 /**
315 * @param array $phrases_in .
316 */
317 private function create_inpost_contextual_info( array $phrases_in ) {
318 if ( ! defined( 'WOOCOMMERCE_PACZKOMATY_INPOST_VERSION' ) ) {
319 $this->add_hookable(
320 new Flexible_Shipping_Contextual_Info(
321 self::METHOD_TITLE_AND_METHOD_DESCRIPTION_ELEMENTS,
322 'inpost',
323 $phrases_in,
324 sprintf(
325 // Translators: link.
326 __( 'Sending your products via InPost? Create the shipments and generate shipping labels directly from your shop using our %1$sInPost integration%2$s', 'flexible-shipping' ),
327 '<a class="oct-btn-more" href="https://octol.io/fs-context-cross-inpost-pl" target="_blank">',
328 '</a>'
329 )
330 )
331 );
332 }
333 }
334
335 /**
336 * @param array $phrases_in .
337 */
338 private function create_dpd_uk_contextual_info( array $phrases_in ) {
339 if ( ! defined( 'WOOCOMMERCE_DPD_UK_VERSION' ) ) {
340 $this->add_hookable(
341 new Flexible_Shipping_Contextual_Info(
342 self::METHOD_TITLE_AND_METHOD_DESCRIPTION_ELEMENTS,
343 'dpd_uk',
344 $phrases_in,
345 sprintf(
346 // Translators: link.
347 __( 'Sending your products via DPD UK? Create the shipments and generate shipping labels directly from your shop using our %1$sDPD UK integration%2$s', 'flexible-shipping' ),
348 '<a class="oct-btn-more" href="https://octol.io/fs-cross-dpd-uk" target="_blank">',
349 '</a>'
350 )
351 )
352 );
353 }
354 }
355
356 /**
357 * Crate default contextual info.
358 *
359 * @param array $phrases_not_in .
360 */
361 private function create_default_contextual_info( array $phrases_not_in ) {
362 $this->add_hookable(
363 new Flexible_Shipping_Contextual_Info(
364 self::METHOD_TITLE_ELEMENT,
365 'other',
366 [],
367 $this->create_html_for_default_contextual_info(),
368 $phrases_not_in
369 )
370 );
371 }
372
373 /**
374 * @return string
375 */
376 private function create_html_for_default_contextual_info() {
377 if ( $this->is_base_location_country_pl() ) {
378 return __( 'Check our further shipping integrations with DPD, DHL, InPost, eNadawca and Orlen Paczka.', 'flexible-shipping' ) . '&nbsp;&nbsp;' .
379 sprintf(
380 // Translators: link.
381 __( '%1$sAdd integrations%2$s', 'flexible-shipping' ),
382 '<a class="oct-btn-more" href="https://octol.io/fs-context-cross-shipping-integrations-pl" target="_blank">',
383 '</a>'
384 );
385 } elseif ( $this->is_base_location_country_gb() ) {
386 return __( 'Check our further shipping integration with DPD UK and FedEx / UPS live rates plugins.', 'flexible-shipping' ) . '&nbsp;&nbsp;' .
387 sprintf(
388 // Translators: link.
389 __( '%1$sAdd integration%2$s', 'flexible-shipping' ),
390 '<a class="oct-btn-more" href="https://octol.io/fs-integrations" target="_blank">',
391 '</a>'
392 );
393 } elseif ( ! defined( 'FLEXIBLE_SHIPPING_PRO_VERSION' ) ) {
394 return __( 'Upgrade from the free version to the Flexible Shipping PRO and create even the most complex shipping scenarios with ease.', 'flexible-shipping' ) . '&nbsp;&nbsp;' .
395 sprintf(
396 // Translators: link.
397 __( '%1$sUpgrade Now%2$s', 'flexible-shipping' ),
398 '<a class="oct-btn-more" href="https://octol.io/fs-context-fs-pro" target="_blank">',
399 '</a>'
400 );
401 } else {
402 return '';
403 }
404 }
405
406 }
407