Update onboarding logic setting task list to hidden (https://github.com/woocommerce/woocommerce-admin/pull/6803)

* Created Admin helper for helper functions

* Only set task_list to hidden on plugin update when store is less then day old

* Add onboarding skipped as well

* Add changelog
This commit is contained in:
louwie17 2021-04-15 11:02:25 -03:00 committed by GitHub
parent 36e7a35ef7
commit 53011ceb27
5 changed files with 66 additions and 17 deletions

View File

@ -94,6 +94,7 @@ Release and roadmap notes are available on the [WooCommerce Developers Blog](htt
- Performance: Avoid updating customer info synchronously from the front end. #6765
- Fix: Set up shipping costs task, redirect to shipping settings after completion. #6791
- Add: Optional children prop to SummaryNumber component #6748
- Fix: Onboarding logic on WooCommerce update to keep task list present. #6803
== 2.2.0 3/30/2021 ==

View File

@ -8,7 +8,7 @@ namespace Automattic\WooCommerce\Admin\Features;
use \Automattic\WooCommerce\Admin\Loader;
use Automattic\WooCommerce\Admin\PageController;
use \Automattic\WooCommerce\Admin\PluginsHelper;
use Automattic\WooCommerce\Admin\WCAdminHelper;
/**
* Contains backend logic for the onboarding profile and checklist feature.
@ -1094,13 +1094,19 @@ class Onboarding {
}
$onboarding_data = get_option( self::PROFILE_DATA_OPTION, array() );
// Don't make updates if the profiler is completed, but task list is potentially incomplete.
if ( isset( $onboarding_data['completed'] ) && $onboarding_data['completed'] ) {
// Don't make updates if the profiler is completed or skipped, but task list is potentially incomplete.
if (
( isset( $onboarding_data['completed'] ) && $onboarding_data['completed'] ) ||
( isset( $onboarding_data['skipped'] ) && $onboarding_data['skipped'] )
) {
return;
}
$onboarding_data['completed'] = true;
update_option( self::PROFILE_DATA_OPTION, $onboarding_data );
update_option( 'woocommerce_task_list_hidden', 'yes' );
if ( ! WCAdminHelper::is_wc_admin_active_for( DAY_IN_SECONDS ) ) {
update_option( 'woocommerce_task_list_hidden', 'yes' );
}
}
}

View File

@ -7,6 +7,8 @@
namespace Automattic\WooCommerce\Admin\Notes;
use Automattic\WooCommerce\Admin\WCAdminHelper;
defined( 'ABSPATH' ) || exit;
/**
@ -20,16 +22,7 @@ trait NoteTraits {
* @return bool Whether or not WooCommerce admin has been active for $seconds.
*/
public static function wc_admin_active_for( $seconds ) {
// Getting install timestamp reference class-wc-admin-install.php.
$wc_admin_installed = get_option( 'woocommerce_admin_install_timestamp', false );
if ( false === $wc_admin_installed ) {
update_option( 'woocommerce_admin_install_timestamp', time() );
return false;
}
return ( ( time() - $wc_admin_installed ) >= $seconds );
return WCAdminHelper::is_wc_admin_active_for( $seconds );
}
/**

View File

@ -5,6 +5,8 @@
namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications;
use Automattic\WooCommerce\Admin\WCAdminHelper;
defined( 'ABSPATH' ) || exit;
/**
@ -17,8 +19,6 @@ class WCAdminActiveForProvider {
* @return number Number of seconds.
*/
public function get_wcadmin_active_for_in_seconds() {
$install_timestamp = get_option( 'woocommerce_admin_install_timestamp' );
return time() - $install_timestamp;
return WCAdminHelper::get_wcadmin_active_for_in_seconds();
}
}

View File

@ -0,0 +1,49 @@
<?php
/**
* WCAdminHelper
*
* Helper class for generic WCAdmin functions.
*/
namespace Automattic\WooCommerce\Admin;
defined( 'ABSPATH' ) || exit;
/**
* Class WCAdminHelper
*/
class WCAdminHelper {
/**
* WC Admin timestamp option name.
*/
const WC_ADMIN_TIMESTAMP_OPTION = 'woocommerce_admin_install_timestamp';
/**
* Get the number of seconds that the store has been active.
*
* @return number Number of seconds.
*/
public static function get_wcadmin_active_for_in_seconds() {
$install_timestamp = get_option( self::WC_ADMIN_TIMESTAMP_OPTION );
if ( false === $install_timestamp ) {
$install_timestamp = time();
update_option( self::WC_ADMIN_TIMESTAMP_OPTION, $install_timestamp );
}
return time() - $install_timestamp;
}
/**
* Test how long WooCommerce Admin has been active.
*
* @param int $seconds Time in seconds to check.
* @return bool Whether or not WooCommerce admin has been active for $seconds.
*/
public static function is_wc_admin_active_for( $seconds ) {
$wc_admin_active_for = self::get_wcadmin_active_for_in_seconds();
return ( $wc_admin_active_for >= $seconds );
}
}