diff --git a/plugins/woocommerce-admin/src/Notes/NoteTraits.php b/plugins/woocommerce-admin/src/Notes/NoteTraits.php new file mode 100644 index 00000000000..4e63bfe75c6 --- /dev/null +++ b/plugins/woocommerce-admin/src/Notes/NoteTraits.php @@ -0,0 +1,36 @@ += $seconds ); + } +} diff --git a/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Facebook_Extension.php b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Facebook_Extension.php index 839cbcc816a..8acb5a13d7b 100644 --- a/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Facebook_Extension.php +++ b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Facebook_Extension.php @@ -15,6 +15,10 @@ defined( 'ABSPATH' ) || exit; * WC_Admin_Notes_Facebook_Extension */ class WC_Admin_Notes_Facebook_Extension { + /** + * Note traits. + */ + use NoteTraits; /** * Name of the note for use in the database. @@ -32,23 +36,15 @@ class WC_Admin_Notes_Facebook_Extension { * Possibly add Facebook extension note. */ public static function possibly_add_facebook_note() { - $wc_admin_installed = get_option( 'wc_admin_install_timestamp', false ); - if ( false === $wc_admin_installed ) { - $wc_admin_installed = time(); - update_option( 'wc_admin_install_timestamp', $wc_admin_installed ); - } - // Only show the Facebook note to stores with products. $products = wp_count_posts( 'product' ); if ( (int) $products->publish < 1 ) { return; } - $current_time = time(); - $three_days_in_seconds = 3 * DAY_IN_SECONDS; - // We want to show the Facebook note after day 3. - if ( $current_time - $wc_admin_installed < $three_days_in_seconds ) { + $three_days_in_seconds = 3 * DAY_IN_SECONDS; + if ( ! self::wc_admin_active_for( $three_days_in_seconds ) ) { return; } diff --git a/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Giving_Feedback_Notes.php b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Giving_Feedback_Notes.php index bec83a58332..1ba1e885ba7 100644 --- a/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Giving_Feedback_Notes.php +++ b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Giving_Feedback_Notes.php @@ -15,6 +15,11 @@ defined( 'ABSPATH' ) || exit; * WC_Admin_Notes_Giving_Feedback_Notes */ class WC_Admin_Notes_Giving_Feedback_Notes { + /** + * Note traits. + */ + use NoteTraits; + /** * Add notes for admin giving feedback. */ @@ -36,18 +41,9 @@ class WC_Admin_Notes_Giving_Feedback_Notes { return; } - // Getting install timestamp reference class-wc-admin-install.php. - $wc_admin_installed = get_option( 'wc_admin_install_timestamp', false ); - if ( false === $wc_admin_installed ) { - $wc_admin_installed = time(); - update_option( 'wc_admin_install_timestamp', $wc_admin_installed ); - } - - $current_time = time(); - $three_days_in_seconds = 259200; - // We need to show Admin Giving feeback notification after 3 days of install. - if ( $current_time - $wc_admin_installed < $three_days_in_seconds ) { + $three_days_in_seconds = 3 * DAY_IN_SECONDS; + if ( ! self::wc_admin_active_for( $three_days_in_seconds ) ) { return; } diff --git a/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Mobile_App.php b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Mobile_App.php index c2e7aeab6b1..6669faa6100 100644 --- a/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Mobile_App.php +++ b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Mobile_App.php @@ -15,6 +15,10 @@ defined( 'ABSPATH' ) || exit; * WC_Admin_Notes_Mobile_App */ class WC_Admin_Notes_Mobile_App { + /** + * Note traits. + */ + use NoteTraits; /** * Name of the note for use in the database. @@ -25,18 +29,9 @@ class WC_Admin_Notes_Mobile_App { * Possibly add mobile app note. */ public static function possibly_add_mobile_app_note() { - - $wc_admin_installed = get_option( 'wc_admin_install_timestamp', false ); - if ( false === $wc_admin_installed ) { - $wc_admin_installed = time(); - update_option( 'wc_admin_install_timestamp', $wc_admin_installed ); - } - - $current_time = time(); - $two_days_in_seconds = 172800; - // We want to show the mobile app note after day 2. - if ( $current_time - $wc_admin_installed < $two_days_in_seconds ) { + $two_days_in_seconds = 2 * DAY_IN_SECONDS; + if ( ! self::wc_admin_active_for( $two_days_in_seconds ) ) { return; }