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0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / packages / woocommerce-admin / src / Features / OnboardingTasks.php
woocommerce / packages / woocommerce-admin / src / Features Last commit date
Navigation 5 years ago ActivityPanels.php 5 years ago Analytics.php 5 years ago AnalyticsDashboard.php 5 years ago Coupons.php 5 years ago CouponsMovedTrait.php 5 years ago CustomerEffortScoreTracks.php 5 years ago Features.php 5 years ago Homescreen.php 5 years ago Marketing.php 5 years ago MobileAppBanner.php 5 years ago Onboarding.php 5 years ago OnboardingTasks.php 5 years ago Settings.php 5 years ago ShippingLabelBanner.php 5 years ago ShippingLabelBannerDisplayRules.php 5 years ago
OnboardingTasks.php
471 lines
1 <?php
2 /**
3 * WooCommerce Onboarding Tasks
4 * NOTE: DO NOT edit this file in WooCommerce core, this is generated from woocommerce-admin.
5 */
6
7 namespace Automattic\WooCommerce\Admin\Features;
8
9 use \Automattic\WooCommerce\Admin\Loader;
10 use Automattic\WooCommerce\Admin\API\Reports\Taxes\Stats\DataStore;
11
12 /**
13 * Contains the logic for completing onboarding tasks.
14 */
15 class OnboardingTasks {
16 /**
17 * Class instance.
18 *
19 * @var OnboardingTasks instance
20 */
21 protected static $instance = null;
22
23 /**
24 * Name of the active task transient.
25 *
26 * @var string
27 */
28 const ACTIVE_TASK_TRANSIENT = 'wc_onboarding_active_task';
29
30 /**
31 * Get class instance.
32 */
33 public static function get_instance() {
34 if ( ! self::$instance ) {
35 self::$instance = new self();
36 }
37 return self::$instance;
38 }
39
40 /**
41 * Constructor
42 */
43 public function __construct() {
44 // This hook needs to run when options are updated via REST.
45 add_action( 'add_option_woocommerce_task_list_complete', array( $this, 'track_completion' ), 10, 2 );
46 add_action( 'add_option_woocommerce_extended_task_list_complete', array( $this, 'track_extended_completion' ), 10, 2 );
47 add_action( 'add_option_woocommerce_task_list_tracked_completed_tasks', array( $this, 'track_task_completion' ), 10, 2 );
48 add_action( 'update_option_woocommerce_task_list_tracked_completed_tasks', array( $this, 'track_task_completion' ), 10, 2 );
49 add_action( 'admin_enqueue_scripts', array( $this, 'update_option_extended_task_list' ), 15 );
50
51 if ( ! is_admin() ) {
52 return;
53 }
54
55 add_action( 'admin_enqueue_scripts', array( $this, 'add_media_scripts' ) );
56 // Old settings injection.
57 // Run after Onboarding.
58 add_filter( 'woocommerce_components_settings', array( __CLASS__, 'component_settings' ), 30 );
59 // New settings injection.
60 add_filter( 'woocommerce_shared_settings', array( $this, 'component_settings' ), 30 );
61
62 add_action( 'admin_init', array( $this, 'set_active_task' ), 5 );
63 add_action( 'admin_enqueue_scripts', array( $this, 'add_onboarding_product_notice_admin_script' ) );
64 add_action( 'admin_enqueue_scripts', array( $this, 'add_onboarding_homepage_notice_admin_script' ) );
65 add_action( 'admin_enqueue_scripts', array( $this, 'add_onboarding_tax_notice_admin_script' ) );
66 add_action( 'admin_enqueue_scripts', array( $this, 'add_onboarding_product_import_notice_admin_script' ) );
67 add_filter( 'woocommerce_paypal_payments_onboarding_redirect_url', array( $this, 'ppcp_ob_after_onboarding_redirect_url' ) );
68 }
69
70 /**
71 * Enqueue scripts and styles.
72 */
73 public function add_media_scripts() {
74 wp_enqueue_media();
75 }
76
77
78
79 /**
80 * Get task item data for settings filter.
81 *
82 * @return array
83 */
84 public static function get_settings() {
85 $settings = array();
86 $wc_pay_is_connected = false;
87 if ( class_exists( '\WC_Payments' ) ) {
88 $wc_payments_gateway = \WC_Payments::get_gateway();
89 $wc_pay_is_connected = method_exists( $wc_payments_gateway, 'is_connected' )
90 ? $wc_payments_gateway->is_connected()
91 : false;
92 }
93
94 $gateways = WC()->payment_gateways->get_available_payment_gateways();
95 $enabled_gateways = array_filter(
96 $gateways,
97 function( $gateway ) {
98 return 'yes' === $gateway->enabled;
99 }
100 );
101
102 // @todo We may want to consider caching some of these and use to check against
103 // task completion along with cache busting for active tasks.
104 $settings['automatedTaxSupportedCountries'] = self::get_automated_tax_supported_countries();
105 $settings['hasHomepage'] = self::check_task_completion( 'homepage' ) || 'classic' === get_option( 'classic-editor-replace' );
106 $settings['hasPaymentGateway'] = ! empty( $enabled_gateways );
107 $settings['enabledPaymentGateways'] = array_keys( $enabled_gateways );
108 $settings['hasPhysicalProducts'] = count(
109 wc_get_products(
110 array(
111 'virtual' => false,
112 'limit' => 1,
113 )
114 )
115 ) > 0;
116 $settings['hasProducts'] = self::check_task_completion( 'products' );
117 $settings['isAppearanceComplete'] = get_option( 'woocommerce_task_list_appearance_complete' );
118 $settings['isTaxComplete'] = self::check_task_completion( 'tax' );
119 $settings['shippingZonesCount'] = count( \WC_Shipping_Zones::get_zones() );
120 $settings['stripeSupportedCountries'] = self::get_stripe_supported_countries();
121 $settings['stylesheet'] = get_option( 'stylesheet' );
122 $settings['taxJarActivated'] = class_exists( 'WC_Taxjar' );
123 $settings['themeMods'] = get_theme_mods();
124 $settings['wcPayIsConnected'] = $wc_pay_is_connected;
125
126 return $settings;
127 }
128
129 /**
130 * Add task items to component settings.
131 *
132 * @param array $settings Component settings.
133 * @return array
134 */
135 public function component_settings( $settings ) {
136 // Bail early if not on a wc-admin powered page, or task list shouldn't be shown.
137 if (
138 ! \Automattic\WooCommerce\Admin\Loader::is_admin_page() ||
139 ! \Automattic\WooCommerce\Admin\Features\Onboarding::should_show_tasks()
140 ) {
141 return $settings;
142 }
143
144 // If onboarding isn't enabled this will throw warnings.
145 if ( ! isset( $settings['onboarding'] ) ) {
146 $settings['onboarding'] = array();
147 }
148
149 $settings['onboarding'] = array_merge(
150 $settings['onboarding'],
151 array(
152 'tasksStatus' => self::get_settings(),
153 )
154 );
155
156 return $settings;
157 }
158
159 /**
160 * Temporarily store the active task to persist across page loads when neccessary (such as publishing a product). Most tasks do not need to do this.
161 */
162 public static function set_active_task() {
163 if ( isset( $_GET[ self::ACTIVE_TASK_TRANSIENT ] ) ) { // phpcs:ignore csrf ok.
164 $task = sanitize_title_with_dashes( wp_unslash( $_GET[ self::ACTIVE_TASK_TRANSIENT ] ) ); // phpcs:ignore csrf ok.
165
166 if ( self::check_task_completion( $task ) ) {
167 return;
168 }
169
170 set_transient(
171 self::ACTIVE_TASK_TRANSIENT,
172 $task,
173 DAY_IN_SECONDS
174 );
175 }
176 }
177
178 /**
179 * Get the name of the active task.
180 *
181 * @return string
182 */
183 public static function get_active_task() {
184 return get_transient( self::ACTIVE_TASK_TRANSIENT );
185 }
186
187 /**
188 * Check for active task completion, and clears the transient.
189 *
190 * @return bool
191 */
192 public static function is_active_task_complete() {
193 $active_task = self::get_active_task();
194
195 if ( ! $active_task ) {
196 return false;
197 }
198
199 if ( self::check_task_completion( $active_task ) ) {
200 delete_transient( self::ACTIVE_TASK_TRANSIENT );
201 return true;
202 }
203
204 return false;
205 }
206
207 /**
208 * Check for task completion of a given task.
209 *
210 * @param string $task Name of task.
211 * @return bool
212 */
213 public static function check_task_completion( $task ) {
214 switch ( $task ) {
215 case 'products':
216 $products = wp_count_posts( 'product' );
217 return (int) $products->publish > 0;
218 case 'homepage':
219 $homepage_id = get_option( 'woocommerce_onboarding_homepage_post_id', false );
220 if ( ! $homepage_id ) {
221 return false;
222 }
223 $post = get_post( $homepage_id );
224 $completed = $post && 'publish' === $post->post_status;
225 return $completed;
226 case 'tax':
227 return 'yes' === get_option( 'wc_connect_taxes_enabled' ) ||
228 count( DataStore::get_taxes( array() ) ) > 0 ||
229 false !== get_option( 'woocommerce_no_sales_tax' );
230 }
231 return false;
232 }
233
234
235 /**
236 * Sets the URL users are redirected to after PayPal Payments has received onboarding information from PayPal.
237 *
238 * @param string $url the current redirect url.
239 * @return string redirect url redirecting to WC Admin home screen.
240 */
241 public static function ppcp_ob_after_onboarding_redirect_url( $url ) {
242 if ( isset( $_GET['ppcpobw'] ) && 1 === absint( $_GET['ppcpobw'] ) ) { // phpcs:ignore csrf ok, sanitization ok.
243 $url = wc_admin_url( '&task=payments&method=paypal&onboarding=complete' );
244 }
245
246 return $url;
247 }
248
249
250 /**
251 * Hooks into the product page to add a notice to return to the task list if a product was added.
252 *
253 * @param string $hook Page hook.
254 */
255 public static function add_onboarding_product_notice_admin_script( $hook ) {
256 global $post;
257 if (
258 'post.php' !== $hook ||
259 'product' !== $post->post_type ||
260 'products' !== self::get_active_task() ||
261 ! self::is_active_task_complete()
262 ) {
263 return;
264 }
265
266 $script_assets_filename = Loader::get_script_asset_filename( 'wp-admin-scripts', 'onboarding-product-notice' );
267 $script_assets = require WC_ADMIN_ABSPATH . WC_ADMIN_DIST_JS_FOLDER . 'wp-admin-scripts/' . $script_assets_filename;
268
269 wp_enqueue_script(
270 'onboarding-product-notice',
271 Loader::get_url( 'wp-admin-scripts/onboarding-product-notice', 'js' ),
272 array_merge( array( WC_ADMIN_APP ), $script_assets ['dependencies'] ),
273 WC_ADMIN_VERSION_NUMBER,
274 true
275 );
276 }
277
278 /**
279 * Hooks into the post page to display a different success notice and sets the active page as the site's home page if visted from onboarding.
280 *
281 * @param string $hook Page hook.
282 */
283 public static function add_onboarding_homepage_notice_admin_script( $hook ) {
284 global $post;
285 if ( 'post.php' === $hook && 'page' === $post->post_type && isset( $_GET[ self::ACTIVE_TASK_TRANSIENT ] ) && 'homepage' === $_GET[ self::ACTIVE_TASK_TRANSIENT ] ) { // phpcs:ignore csrf ok.
286 $script_assets_filename = Loader::get_script_asset_filename( 'wp-admin-scripts', 'onboarding-homepage-notice' );
287 $script_assets = require WC_ADMIN_ABSPATH . WC_ADMIN_DIST_JS_FOLDER . 'wp-admin-scripts/' . $script_assets_filename;
288
289 wp_enqueue_script(
290 'onboarding-homepage-notice',
291 Loader::get_url( 'wp-admin-scripts/onboarding-homepage-notice', 'js' ),
292 array_merge( array( WC_ADMIN_APP ), $script_assets ['dependencies'] ),
293 WC_ADMIN_VERSION_NUMBER,
294 true
295 );
296 }
297 }
298
299 /**
300 * Adds a notice to return to the task list when the save button is clicked on tax settings pages.
301 */
302 public static function add_onboarding_tax_notice_admin_script() {
303 $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; // phpcs:ignore csrf ok, sanitization ok.
304 $tab = isset( $_GET['tab'] ) ? $_GET['tab'] : ''; // phpcs:ignore csrf ok, sanitization ok.
305
306 if (
307 'wc-settings' === $page &&
308 'tax' === $tab &&
309 'tax' === self::get_active_task() &&
310 ! self::is_active_task_complete()
311 ) {
312 $script_assets_filename = Loader::get_script_asset_filename( 'wp-admin-scripts', 'onboarding-tax-notice' );
313 $script_assets = require WC_ADMIN_ABSPATH . WC_ADMIN_DIST_JS_FOLDER . 'wp-admin-scripts/' . $script_assets_filename;
314
315 wp_enqueue_script(
316 'onboarding-tax-notice',
317 Loader::get_url( 'wp-admin-scripts/onboarding-tax-notice', 'js' ),
318 array_merge( array( WC_ADMIN_APP ), $script_assets ['dependencies'] ),
319 WC_ADMIN_VERSION_NUMBER,
320 true
321 );
322 }
323 }
324
325 /**
326 * Adds a notice to return to the task list when the product importeris done running.
327 *
328 * @param string $hook Page hook.
329 */
330 public function add_onboarding_product_import_notice_admin_script( $hook ) {
331 $step = isset( $_GET['step'] ) ? $_GET['step'] : ''; // phpcs:ignore csrf ok, sanitization ok.
332 if ( 'product_page_product_importer' === $hook && 'done' === $step && 'product-import' === self::get_active_task() ) {
333 delete_transient( self::ACTIVE_TASK_TRANSIENT );
334
335 $script_assets_filename = Loader::get_script_asset_filename( 'wp-admin-scripts', 'onboarding-product-import-notice' );
336 $script_assets = require WC_ADMIN_ABSPATH . WC_ADMIN_DIST_JS_FOLDER . 'wp-admin-scripts/' . $script_assets_filename;
337
338 wp_enqueue_script(
339 'onboarding-product-import-notice',
340 Loader::get_url( 'wp-admin-scripts/onboarding-product-import-notice', 'js' ),
341 array_merge( array( WC_ADMIN_APP ), $script_assets ['dependencies'] ),
342 WC_ADMIN_VERSION_NUMBER,
343 true
344 );
345 }
346 }
347
348 /**
349 * Get an array of countries that support automated tax.
350 *
351 * @return array
352 */
353 public static function get_automated_tax_supported_countries() {
354 // https://developers.taxjar.com/api/reference/#countries .
355 $tax_supported_countries = array_merge(
356 array( 'US', 'CA', 'AU' ),
357 WC()->countries->get_european_union_countries()
358 );
359
360 return $tax_supported_countries;
361 }
362
363 /**
364 * Returns a list of Stripe supported countries. This method can be removed once merged to core.
365 *
366 * @return array
367 */
368 private static function get_stripe_supported_countries() {
369 // https://stripe.com/global.
370 return array(
371 'AU',
372 'AT',
373 'BE',
374 'BG',
375 'BR',
376 'CA',
377 'CY',
378 'CZ',
379 'DK',
380 'EE',
381 'FI',
382 'FR',
383 'DE',
384 'GR',
385 'HK',
386 'IN',
387 'IE',
388 'IT',
389 'JP',
390 'LV',
391 'LT',
392 'LU',
393 'MY',
394 'MT',
395 'MX',
396 'NL',
397 'NZ',
398 'NO',
399 'PL',
400 'PT',
401 'RO',
402 'SG',
403 'SK',
404 'SI',
405 'ES',
406 'SE',
407 'CH',
408 'GB',
409 'US',
410 'PR',
411 );
412 }
413
414 /**
415 * Records an event when all tasks are completed in the task list.
416 *
417 * @param mixed $old_value Old value.
418 * @param mixed $new_value New value.
419 */
420 public static function track_completion( $old_value, $new_value ) {
421 if ( $new_value ) {
422 wc_admin_record_tracks_event( 'tasklist_tasks_completed' );
423 }
424 }
425
426 /**
427 * Records an event when all tasks are completed in the extended task list.
428 *
429 * @param mixed $old_value Old value.
430 * @param mixed $new_value New value.
431 */
432 public static function track_extended_completion( $old_value, $new_value ) {
433 if ( $new_value ) {
434 wc_admin_record_tracks_event( 'extended_tasklist_tasks_completed' );
435 }
436 }
437
438 /**
439 * Records an event for individual task completion.
440 *
441 * @param mixed $old_value Old value.
442 * @param mixed $new_value New value.
443 */
444 public static function track_task_completion( $old_value, $new_value ) {
445 $old_value = is_array( $old_value ) ? $old_value : array();
446 $untracked_tasks = array_diff( $new_value, $old_value );
447
448 foreach ( $untracked_tasks as $task ) {
449 wc_admin_record_tracks_event( 'tasklist_task_completed', array( 'task_name' => $task ) );
450 }
451 }
452
453 /**
454 * Update registered extended task list items.
455 */
456 public static function update_option_extended_task_list() {
457 if (
458 ! \Automattic\WooCommerce\Admin\Loader::is_admin_page() ||
459 ! \Automattic\WooCommerce\Admin\Features\Onboarding::should_show_tasks()
460 ) {
461 return;
462 }
463 $extended_tasks_list_items = get_option( 'woocommerce_extended_task_list_items', array() );
464 $registered_extended_tasks_list_items = apply_filters( 'woocommerce_get_registered_extended_tasks', array() );
465 if ( $registered_extended_tasks_list_items !== $extended_tasks_list_items ) {
466 update_option( 'woocommerce_extended_task_list_items', $registered_extended_tasks_list_items );
467 update_option( 'woocommerce_extended_task_list_hidden', 'no' );
468 }
469 }
470 }
471