PluginProbe
WooCommerce Square / 2.1.2
WooCommerce Square v2.1.2
5.5.0 5.4.3 5.4.2 5.4.1 5.4.0 trunk 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 All 132 releases
woocommerce-square / includes / Plugin.php

Plugin.php in WooCommerce Square 2.1.2, at includes/Plugin.php

899 lines 25.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WooCommerce Square
4 *
5 * This source file is subject to the GNU General Public License v3.0
6 * that is bundled with this package in the file license.txt.
7 * It is also available through the world-wide-web at this URL:
8 * http://www.gnu.org/licenses/gpl-3.0.html
9 * If you did not receive a copy of the license and are unable to
10 * obtain it through the world-wide-web, please send an email
11 * to license@woocommerce.com so we can send you a copy immediately.
12 *
13 * DISCLAIMER
14 *
15 * Do not edit or add to this file if you wish to upgrade WooCommerce Square to newer
16 * versions in the future. If you wish to customize WooCommerce Square for your
17 * needs please refer to https://docs.woocommerce.com/document/woocommerce-square/
18 *
19 * @author WooCommerce
20 * @copyright Copyright: (c) 2019, Automattic, Inc.
21 * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
22 */
23
24 namespace WooCommerce\Square;
25
26 defined( 'ABSPATH' ) or exit;
27
28 use SkyVerge\WooCommerce\PluginFramework\v5_4_0 as Framework;
29 use WooCommerce\Square\Handlers\Background_Job;
30 use WooCommerce\Square\Handlers\Email;
31 use WooCommerce\Square\Handlers\Order;
32 use WooCommerce\Square\Handlers\Product;
33 use WooCommerce\Square\Handlers\Sync;
34 use WooCommerce\Square\Handlers\Products;
35
36 /**
37 * The main plugin class.
38 *
39 * @since 2.0.0
40 */
41 class Plugin extends Framework\SV_WC_Payment_Gateway_Plugin {
42
43
44 /** plugin version number */
45 const VERSION = '2.1.2';
46
47 /** plugin ID */
48 const PLUGIN_ID = 'square';
49
50 /** string gateway ID */
51 const GATEWAY_ID = 'square_credit_card';
52
53
54 /** @var Plugin plugin instance */
55 protected static $instance;
56
57 /** @var Settings settings handler instance */
58 private $settings_handler;
59
60 /** @var Handlers\Connection connection handler instance */
61 private $connection_handler;
62
63 /** @var Admin admin handler instance */
64 private $admin_handler;
65
66 /** @var Sync sync handler instance */
67 private $sync_handler;
68
69 /** @var Background_Job background handler instance */
70 private $background_job_handler;
71
72 /** @var AJAX handler instance */
73 private $ajax_handler;
74
75 /** @var Email emails handler */
76 private $email_handler;
77
78 /** @var Order orders handler */
79 private $order_handler;
80
81 /** @var Products products handler */
82 private $products_handler;
83
84 /**
85 * Constructs the plugin.
86 *
87 * @since 2.0.0
88 */
89 public function __construct() {
90
91 parent::__construct(
92 self::PLUGIN_ID,
93 self::VERSION,
94 [
95 'text_domain' => 'woocommerce-square',
96 'gateways' => [ self::GATEWAY_ID => Gateway::class ],
97 'require_ssl' => true,
98 'supports' => [
99 self::FEATURE_CAPTURE_CHARGE,
100 self::FEATURE_CUSTOMER_ID,
101 self::FEATURE_MY_PAYMENT_METHODS,
102 ],
103 'dependencies' => [
104 'php_extensions' => [ 'curl', 'json', 'mbstring' ],
105 ],
106 ]
107 );
108
109 $this->includes();
110
111 /**
112 * Fires upon plugin loaded (legacy hook).
113 *
114 * @since 1.0.0
115 */
116 do_action( 'wc_square_loaded' );
117
118 add_action( 'woocommerce_register_taxonomy', [ $this, 'init_taxonomies' ] );
119
120 add_filter( 'woocommerce_locate_template', [ $this, 'locate_template' ], 20, 3 );
121 add_filter( 'woocommerce_locate_core_template', [ $this, 'locate_template' ], 20, 3 );
122 }
123
124
125 /**
126 * Includes required classes.
127 *
128 * @since 2.0.0
129 */
130 private function includes() {
131
132 $this->connection_handler = new Handlers\Connection( $this );
133
134 $this->sync_handler = new Sync( $this );
135
136 // background export must be loaded all the time, because otherwise background jobs simply won't work
137 require_once $this->get_framework_path() . '/utilities/class-sv-wp-async-request.php';
138 require_once $this->get_framework_path() . '/utilities/class-sv-wp-background-job-handler.php';
139 require_once $this->get_framework_path() . '/utilities/class-sv-wp-job-batch-handler.php';
140
141 $this->background_job_handler = new Background_Job();
142
143 $this->ajax_handler = new AJAX();
144
145 $this->email_handler = new Email();
146
147 $this->order_handler = new Order();
148 }
149
150
151 /**
152 * Adds API request logging.
153 *
154 * @internal
155 *
156 * @since 2.0.0
157 */
158 public function add_api_request_logging() {
159
160 if ( ! has_action( 'wc_' . $this->get_id() . '_api_request_performed' ) ) {
161 add_action( 'wc_' . $this->get_id() . '_api_request_performed', [ $this, 'log_api_request' ], 10, 2 );
162 }
163 }
164
165
166 /**
167 * Logs an API request & response.
168 *
169 * @since 2.0.0
170 *
171 * @param array $request request data
172 * @param array $response response data
173 * @param string|null $log_id log ID
174 */
175 public function log_api_request( $request, $response, $log_id = null ) {
176
177 if ( $this->get_settings_handler() && $this->get_settings_handler()->is_debug_enabled() ) {
178 parent::log_api_request( $request, $response, $log_id );
179 }
180 }
181
182
183 /**
184 * Initializes the lifecycle handler.
185 *
186 * @since 2.0.0
187 */
188 public function init_lifecycle_handler() {
189
190 $this->lifecycle_handler = new Lifecycle( $this );
191 }
192
193
194 /**
195 * Registers custom taxonomies.
196 *
197 * @internal
198 *
199 * @since 2.0.0
200 */
201 public function init_taxonomies() {
202
203 Product::init_taxonomies();
204 }
205
206
207 /**
208 * Initializes the general plugin functionality.
209 *
210 * @since 2.0.0
211 */
212 public function init_plugin() {
213
214 $this->settings_handler = new Settings( $this );
215 $this->products_handler = new Products( $this );
216
217 if ( ! $this->admin_handler && is_admin() ) {
218 $this->admin_handler = new Admin( $this );
219 }
220 }
221
222
223 /**
224 * Locates the WooCommerce template files from our templates directory.
225 *
226 * @internal
227 *
228 * @since 2.0.0
229 *
230 * @param string $template already found template
231 * @param string $template_name searchable template name
232 * @param string $template_path template path
233 * @return string search result for the template
234 */
235 public function locate_template( $template, $template_name, $template_path ) {
236
237 // only keep looking if no custom theme template was found
238 // or if a default WooCommerce template was found
239 if ( ! $template || Framework\SV_WC_Helper::str_starts_with( $template, WC()->plugin_path() ) ) {
240
241 // set the path to our templates directory
242 $plugin_path = $this->get_plugin_path() . '/templates/';
243
244 // if a template is found, make it so
245 if ( is_readable( $plugin_path . $template_name ) ) {
246 $template = $plugin_path . $template_name;
247 }
248 }
249
250 return $template;
251 }
252
253
254 /** Admin methods *************************************************************************************************/
255
256
257 /**
258 * Adds admin notices.
259 *
260 * @since 2.0.0
261 */
262 public function add_admin_notices() {
263
264 parent::add_admin_notices();
265
266 // show any one-off messages
267 $this->get_message_handler()->show_messages();
268
269 // display a notice if the auto-refresh failed
270 if ( get_option( 'wc_' . $this->get_id() . '_refresh_failed', false ) ) {
271
272 $message = sprintf(
273 __( 'Heads up! There may be a problem with your connection to Square. In order to continue accepting payments, please %1$sdisconnect and re-connect your site%2$s.', 'woocommerce-square' ),
274 '<a href="' . esc_url( $this->get_settings_url() ) . '">', '</a>'
275 );
276
277 $this->get_admin_notice_handler()->add_admin_notice( $message, 'refresh-failed', [
278 'dismissible' => false,
279 'notice_class' => 'notice-warning',
280 ] );
281 }
282
283 if ( $this->get_settings_handler()->is_connected() ) {
284
285 $message = '<strong>' . __( 'You are connected to Square!', 'woocommerce-square' ) . '</strong>';
286
287 // prompt to set a location if not set
288 if ( ! $this->get_settings_handler()->get_location_id() ) {
289
290 if ( $this->is_plugin_settings() ) {
291
292 $instruction = __( 'To get started, set your business location.', 'woocommerce-square' );
293
294 } else {
295
296 $instruction = sprintf(
297 /* translators: Placeholders: %1$s - <a> tag, %2$s - </a> tag */
298 __( 'Visit the %1$splugin settings%2$s to set your business location.', 'woocommerce-square' ),
299 '<a href="' . esc_url( $this->get_settings_url() ) . '">', '</a>'
300 );
301 }
302
303 $this->get_admin_notice_handler()->add_admin_notice( $message . ' ' . $instruction, 'set-location' );
304
305 } elseif ( ! $this->get_sync_handler()->get_last_synced_at() && $this->get_settings_handler()->is_product_sync_enabled() ) {
306
307 $message = __( 'You are ready to sync products!', 'woocommerce-square' );
308
309 if ( ! empty( Product::get_products_synced_with_square() ) ) {
310
311 $instruction = sprintf(
312 /* translators: Placeholders: %1$s - <strong> tag, %2$s - product count, %3$s - </strong> tag, %4$s - <a> tag, %5$s - </a> tag */
313 __( '%1$s%2$d products%3$s are marked "sync with Square". %4$sStart a new sync now &raquo;%5$s', 'woocommerce-square' ),
314 '<strong>', count( Product::get_products_synced_with_square() ), '</strong>',
315 '<a href="' . esc_url( add_query_arg( 'section', 'update', $this->get_settings_url() ) ) . '">', '</a>'
316 );
317
318 } else {
319
320 $instruction = sprintf(
321 /* translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag, %3$s - <a> tag, %4$s - </a> tag */
322 __( '%1$sNo products%2$s are marked "sync with Square". %3$sUpdate your products to sync data &raquo;%4$s', 'woocommerce-square' ),
323 '<strong>', '</strong>',
324 '<a href="' . esc_url( admin_url( 'edit.php?post_type=product' ) ) . '">', '</a>'
325 );
326 }
327
328 $this->get_admin_notice_handler()->add_admin_notice( $message . ' ' . $instruction, 'set-location' );
329 }
330
331 // a notice for when WC stock handling is globally disabled
332 if ( 'yes' !== get_option( 'woocommerce_manage_stock' ) && $this->get_settings_handler()->is_inventory_sync_enabled() ) {
333
334 $message = sprintf(
335 __( 'Heads up! Square is configured to sync product inventory, but WooCommerce stock management is disabled. Please %1$senable stock management%2$s to ensure product inventory counts are kept in sync.', 'woocommerce-square' ),
336 '<a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=products&section=inventory' ) ) . '">', '</a>'
337 );
338
339 $this->get_admin_notice_handler()->add_admin_notice( $message, 'enable-wc-sync', [
340 'notice_class' => 'notice-warning',
341 ] );
342 }
343
344 } else {
345
346 if ( $this->is_plugin_settings() ) {
347
348 $instruction = __( 'To get started, connect with Square.', 'woocommerce-square' );
349
350 } else {
351
352 $instruction = sprintf(
353 /* translators: Placeholders: %1$s - <a> tag, %2$s - </a> tag */
354 __( 'To get started, %1$sconnect with Square &raquo;%2$s', 'woocommerce-square' ),
355 '<a href="' . esc_url( $this->get_settings_url() ) . '">', '</a>'
356 );
357 }
358
359 $message = sprintf(
360 /* translators: Placeholders: %1$s - plugin name */
361 __( 'Thanks for installing %1$s!', 'woocommerce-square' ),
362 esc_html( $this->get_plugin_name() )
363 );
364
365 $this->get_admin_notice_handler()->add_admin_notice( $message . ' ' . $instruction, 'connect' );
366 }
367
368 // add a notice for out-of-bounds base locations
369 $this->add_base_location_admin_notice();
370
371 // add a notice when background processing is not supported
372 $this->add_background_processing_notice();
373
374 // add a notice when no refresh token is available
375 $this->add_missing_refresh_token_notice();
376
377 // add a tax-inclusive warning to product pages
378 $this->add_tax_inclusive_pricing_notice();
379
380 if ( get_option( 'wc_square_updated_to_2_0_0' ) ) {
381
382 $this->get_admin_notice_handler()->add_admin_notice(
383 sprintf(
384 /* translators: Placeholders: %1$s - plugin name, %2$ - plugin version number, %3$s - opening <a> HTML link tag, %4$s - closing </a> HTML link tag, %5$s - opening <a> HTML link tag, %6$s - closing </a> HTML link tag*/
385 esc_html__( '%1$s has been updated to version %2$s. In order to continue syncing product inventory, please make sure to disconnect and reconnect with Square from the %3$splugin settings%4$s and re-sync your products. Read more in the %5$supdated documentation%6$s.', 'woocommerce-square' ),
386 '<strong>' . esc_html( $this->get_plugin_name() ) . '</strong>',
387 $this->get_version(),
388 '<a href="' . esc_url( $this->get_settings_url() ) . '">', '</a>',
389 '<a href="' . esc_url( $this->get_documentation_url() ) . '">', '</a>'
390 ),
391 'updated-to-v2',
392 [ 'notice_class' => 'notice-warning' ]
393 );
394 }
395 }
396
397
398 /**
399 * Adds a notice for out-of-bounds base locations.
400 *
401 * @since 2.0.0
402 */
403 protected function add_base_location_admin_notice() {
404
405 $accepted_countries = [
406 'US',
407 'CA',
408 'GB',
409 'AU',
410 'JP',
411 ];
412
413 $base_location = wc_get_base_location();
414
415 if ( isset( $base_location['country'] ) && ! in_array( $base_location['country'], $accepted_countries, true ) ) {
416
417 $this->get_admin_notice_handler()->add_admin_notice( sprintf(
418 /* translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag, %3$s - 2-character country code, %4$s - comma separated list of 2-character country codes */
419 __( '%1$sWooCommerce Square:%2$s Your base country is %3$s, but Square can’t accept transactions from merchants outside of %4$s.', 'woocommerce-square' ),
420 '<strong>', '</strong>',
421 esc_html( $base_location['country'] ),
422 esc_html( Framework\SV_WC_Helper::list_array_items( $accepted_countries ) )
423 ), 'wc-square-base-location', [
424 'notice_class' => 'notice-error',
425 ] );
426 }
427 }
428
429
430 /**
431 * Adds a notice when background processing is not supported.
432 *
433 * @since 2.0.0
434 */
435 protected function add_background_processing_notice() {
436
437 if ( $this->get_settings_handler()->is_product_sync_enabled() && ! $this->get_background_job_handler()->test_connection() ) {
438
439 $this->get_admin_notice_handler()->add_admin_notice( sprintf(
440 /* translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag, %3$s - <a> tag, %4$s - </a> tag */
441 __( '%1$sWooCommerce Square:%2$s It looks like your site does not support background processing, which means large numbers of products may not sync successfully with Square. %3$sRead more here%4$s on how to resolve this.', 'woocommerce-square' ),
442 '<strong>', '</strong>',
443 '<a href="https://docs.woocommerce.com/document/woocommerce-square/#sync-issues" target="_blank">', '</a>'
444 ), 'wc-square-background-processing', [
445 'notice_class' => 'notice-warning',
446 ] );
447 }
448 }
449
450 /**
451 * Adds a notice if no refresh token has been cached.
452 *
453 * @since 2.0.5
454 */
455 protected function add_missing_refresh_token_notice() {
456 if ( $this->get_settings_handler()->is_sandbox() ) {
457 return;
458 }
459
460 $refresh_token = '';
461 $settings_handler = $this->get_settings_handler();
462
463 if ( method_exists( $settings_handler, 'get_access_token' ) ) {
464 $access_token = $settings_handler->get_access_token();
465 if ( empty( $access_token ) ) {
466 // We are already in a disconnected state, don't show the warning.
467 return;
468 }
469 }
470
471 if ( method_exists( $settings_handler, 'get_refresh_token' ) ) {
472 $refresh_token = $settings_handler->get_refresh_token();
473 }
474
475 if ( empty( $refresh_token ) ) {
476 $this->get_admin_notice_handler()->add_admin_notice(
477 sprintf(
478 /* translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag, %3$s - <a> tag, %4$s - </a> tag */
479 __( '%1$sWooCommerce Square:%2$s Automatic refreshing of the connection to Square is inactive. Please disconnect and reconnect to resolve.', 'woocommerce-square' ),
480 '<strong>',
481 '</strong>'
482 ),
483 'wc-square-missing-refresh-token',
484 [
485 'dismissible' => false,
486 'notice_class' => 'notice-error',
487 ]
488 );
489 }
490 }
491
492
493 /**
494 * Adds a tax-inclusive admin warning to product pages.
495 *
496 * @since 2.0.0
497 */
498 protected function add_tax_inclusive_pricing_notice() {
499 global $typenow;
500
501 // only show on product edit pages when configured that prices include tax
502 if ( 'product' === $typenow && isset( $_GET['action'], $_GET['post'] ) && 'edit' === $_GET['action'] && wc_prices_include_tax() && $this->get_settings_handler()->is_product_sync_enabled() ) {
503
504 $product = wc_get_product( (int) $_GET['post'] );
505
506 // only show for products configured as taxable and sync with Square
507 if ( $product instanceof \WC_Product && $product->is_taxable() && Product::is_synced_with_square( $product ) ) {
508
509 $this->get_admin_notice_handler()->add_admin_notice( sprintf(
510 __( '%1$sWooCommerce Square:%2$s Product prices are entered inclusive of tax, but Square does not support syncing tax-inclusive prices. Please make sure your Square tax rates match your WooCommerce tax rates.', 'woocommerce-square' ),
511 '<strong>', '</strong>'
512 ), 'wc-square-tax-inclusive', [
513 'notice_class' => 'notice-warning',
514 ] );
515 }
516 }
517 }
518
519
520 /**
521 * Adds admin notices for currency issues.
522 *
523 * @since 2.0.0
524 */
525 protected function add_currency_admin_notices() {
526
527 parent::add_currency_admin_notices();
528
529 if ( isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && $this->get_settings_handler()->is_connected() ) {
530
531 foreach ( $this->get_settings_handler()->get_locations() as $location ) {
532
533 if ( $this->get_settings_handler()->get_location_id() === $location->getId() && get_woocommerce_currency() !== $location->getCurrency() ) {
534
535 $this->get_admin_notice_handler()->add_admin_notice( sprintf(
536 __( 'Heads up! Your store currency is %1$s but your configured Square business location currency is %2$s, so payments cannot be processed. Please %3$schoose a different business location%4$s or change your %5$sshop currency%6$s.', 'woocommerce-square' ),
537 '<strong>' . esc_html( get_woocommerce_currency() ) . '</strong>',
538 '<strong>' . esc_html( $location->getCurrency() ) . '</strong>',
539 '<a href="' . esc_url( $this->get_settings_url() ) . '">', '</a>',
540 '<a href="' . esc_url( admin_url( 'admin.php?page=wc-settings' ) ) . '">', '</a>'
541 ), 'wc-square-currency-mismatch', [
542 'notice_class' => 'notice-error',
543 ] );
544 }
545 }
546 }
547 }
548
549
550 /** Helper methods ************************************************************************************************/
551
552
553 /**
554 * Returns an idempotency key to be used in Square API requests.
555 *
556 * @since 2.0.0
557 *
558 * @param string $key_input
559 * @return string
560 */
561 public function get_idempotency_key( $key_input = '' ) {
562
563 if ( '' === $key_input ) {
564 $key_input = uniqid( '', false );
565 }
566
567 /**
568 * Filters an idempotency key.
569 *
570 * @since 2.0.0
571 *
572 * @param string $key_input
573 */
574 return apply_filters( 'wc_square_idempotency_key', md5( get_option( 'siteurl' ) ) . ':' . $key_input );
575 }
576
577
578 /** Conditional methods *******************************************************************************************/
579
580
581 /**
582 * Determines if viewing the plugin settings.
583 *
584 * @since 2.0.0
585 *
586 * @return bool
587 */
588 public function is_plugin_settings() {
589
590 return parent::is_plugin_settings() || ( isset( $_GET['page'], $_GET['tab'] ) && 'wc-settings' === $_GET['page'] && self::PLUGIN_ID === $_GET['tab'] );
591 }
592
593
594 /** Getter methods ************************************************************************************************/
595
596
597 /**
598 * Gets the main Square API handler.
599 *
600 * @since 2.0.0
601 *
602 * @param string|null $access_token API access token
603 * @return API
604 */
605 public function get_api( $access_token = null, $is_sandbox = null ) {
606
607 if ( ! $access_token ) {
608 $access_token = $this->get_settings_handler()->get_access_token();
609 }
610
611 if ( is_null( $is_sandbox ) ) {
612 $is_sandbox = $this->get_settings_handler()->is_sandbox();
613 }
614
615 return new API( $access_token, $is_sandbox );
616 }
617
618
619 /**
620 * Gets the connection handler.
621 *
622 * @since 2.0.0
623 *
624 * @return Handlers\Connection
625 */
626 public function get_connection_handler() {
627
628 return $this->connection_handler;
629 }
630
631
632 /**
633 * Gets the sync handler instance.
634 *
635 * @since 2.0.0
636 *
637 * @return Sync
638 */
639 public function get_sync_handler() {
640
641 return $this->sync_handler;
642 }
643
644
645 /**
646 * Gets the background sync handler instance.
647 *
648 * @since 2.0.0
649 *
650 * @return Background_Job
651 */
652 public function get_background_job_handler() {
653
654 return $this->background_job_handler;
655 }
656
657
658 /**
659 * Gets the settings handler instance.
660 *
661 * @since 2.0.0
662 *
663 * @return Settings
664 */
665 public function get_settings_handler() {
666
667 return $this->settings_handler;
668 }
669
670
671 /**
672 * Gets the admin handler instance.
673 *
674 * @since 2.0.0
675 *
676 * @return Admin|null
677 */
678 public function get_admin_handler() {
679
680 // throw a notice if calling before admin_init
681 Framework\SV_WC_Helper::maybe_doing_it_early( 'admin_init', __METHOD__, '2.0.0' );
682
683 return $this->admin_handler;
684 }
685
686
687 /**
688 * Gets the email handler instance.
689 *
690 * @since 2.0.0
691 *
692 * @return Email
693 */
694 public function get_email_handler() {
695
696 return $this->email_handler;
697 }
698
699
700 /**
701 * Gets the order handler instance.
702 *
703 * @since 2.0.0
704 *
705 * @return Order
706 */
707 public function get_order_handler() {
708
709 return $this->order_handler;
710 }
711
712 /**
713 * Get the products handler instance/
714 *
715 * @since 2.0.8
716 *
717 * @return Products
718 */
719 public function get_products_handler() {
720 return $this->products_handler;
721 }
722
723
724 /**
725 * Gets the deprecated hook details.
726 *
727 * @see Framework\SV_WC_Hook_Deprecator
728 *
729 * @since 2.0.0
730 *
731 * @return array
732 */
733 protected function get_deprecated_hooks() {
734
735 // the following are filters, except when an action is explicitly mentioned
736 $v2_0_0_removed_hooks = [
737
738 // to filter the locale, the default WordPress filter should be used:
739 'woocommerce_square_plugin_locale' => [ 'replacement' => 'plugin_locale', 'map' => true ],
740
741 // sync square product variation properties
742 'woocommerce_square_currency' => [], // used when passing a WooCommerce product price into a Square ItemVariation
743 'wc_square_sync_to_square_price' => [], // used when passing a WooCommerce product price into a Square ItemVariation
744 'woocommerce_square_format_price' => [], // formats the price coming from Square
745 'woocommerce_square_sync_from_square_description' => [], // flag whether to add a description to created item
746
747 // we no longer filter inventory type in v2.0.0 and timeout is handled by background job differently
748 'woocommerce_square_inventory_type' => [],
749 'woocommerce_square_inventory_sync_timeout_limit' => [],
750 'woocommerce_square_inventory_poll_frequency' => [],
751
752 // Square payment
753 'woocommerce_square_payment_form_trigger_element' => [],
754 'woocommerce_square_payment_order_note' => [ 'replacement' => 'wc_square_payment_order_note', 'map' => true ],
755 'woocommerce_square_description' => [], // front end payment fields description
756
757 // most gateway properties and settings can be mapped to new filters:
758 'woocommerce_square_api_url' => [ 'replacement' => 'wc_square_api_url', 'map' => true ], // filter is reinstated with name change for consistency
759 'woocommerce_square_payment_gateway_is_available' => [ 'replacement' => 'wc_gateway_square_credit_card_is_available', 'map' => true ], // filter handled by SkyVerge Framework
760 'woocommerce_square_integration_settings_args' => [ 'replacement' => 'woocommerce_settings_api_form_fields_square', 'map' => true ], // filters gateway settings
761 'woocommerce_square_integration_custom_settings' => [ 'replacement' => 'woocommerce_settings_tabs_square', 'map' => true ], // settings action hook
762
763 // API requests filters, these are handled differently and can't be mapped:
764 'woocommerce_square_request_args' => [],
765 'woocommerce_square_request_retries' => [],
766
767 // transients are no longer used to handle these cache types:
768 'woocommerce_square_business_location_cache' => [],
769 'woocommerce_square_item_sku_cache' => [],
770 'woocommerce_square_inventory_cache' => [],
771 'woocommerce_square_sync_processing_ids_cache' => [],
772 'woocommerce_square_manual_sync_processing_cache' => [],
773 'woocommerce_square_syncing_square_ids_cache' => [],
774 'woocommerce_square_syncing_wc_product_ids_cache' => [],
775
776 // when a bulk sync action is triggered (action hook):
777 'woocommerce_square_bulk_syncing_square_to_wc' => [],
778
779 // get_posts args filter, the new implementation has different scope:
780 'woocommerce_square_get_all_product_ids_args' => [],
781
782 // idempotency key
783 'woocommerce_square_idempotency_key' => [ 'replacement' => 'wc_square_idempotency_key', 'map' => true ],
784
785 ];
786
787 // add common array data for all removed hooks in version 2.0.0
788 foreach ( array_keys( $v2_0_0_removed_hooks ) as $hook_name ) {
789 $v2_0_0_removed_hooks[ $hook_name ]['version'] = '2.0.0';
790 $v2_0_0_removed_hooks[ $hook_name ]['removed'] = true;
791 }
792
793 return $v2_0_0_removed_hooks;
794 }
795
796
797 /**
798 * Gets the plugin name.
799 *
800 * @since 2.0.0
801 *
802 * @return string
803 */
804 public function get_plugin_name() {
805
806 return __( 'WooCommerce Square', 'woocommerce-square' );
807 }
808
809
810 /**
811 * Gets the settings URL.
812 *
813 * @since 2.0.0
814 *
815 * @param null|string $gateway_id gateway ID
816 * @return string
817 */
818 public function get_settings_url( $gateway_id = null ) {
819
820 $params = [
821 'page' => 'wc-settings',
822 'tab' => self::PLUGIN_ID,
823 ];
824
825 return add_query_arg( $params, admin_url( 'admin.php' ) );
826 }
827
828
829 /**
830 * Gets the sale page URL.
831 *
832 * @since 2.0.0
833 *
834 * @return string
835 */
836 public function get_sales_page_url() {
837
838 return 'https://woocommerce.com/products/woocommerce-square/';
839 }
840
841
842 /**
843 * Gets the documentation URL.
844 *
845 * @since 2.0.0
846 *
847 * @return string
848 */
849 public function get_documentation_url() {
850
851 return 'https://docs.woocommerce.com/document/woocommerce-square/';
852 }
853
854
855 /**
856 * Gets the support URL.
857 *
858 * @since 2.0.0
859 *
860 * @return string
861 */
862 public function get_support_url() {
863
864 return 'https://wordpress.org/support/plugin/woocommerce-square/'; // TODO: confirm this
865 }
866
867
868 /**
869 * Gets __DIR__.
870 *
871 * @since 2.0.0
872 *
873 * @return string
874 */
875 protected function get_file() {
876
877 return __DIR__;
878 }
879
880
881 /**
882 * Gets the singleton instance of the plugin.
883 *
884 * @since 2.0.0
885 *
886 * @return Plugin
887 */
888 public static function instance() {
889
890 if ( null === self::$instance ) {
891 self::$instance = new self();
892 }
893
894 return self::$instance;
895 }
896
897
898 }
899