2019-03-12 13:13:20 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* WooCommerce Admin: Historical Analytics Data Note.
|
|
|
|
*
|
|
|
|
* Adds a notes to store alerts area concerning the historial analytics data tool.
|
|
|
|
*/
|
|
|
|
|
2019-07-31 19:47:32 +00:00
|
|
|
namespace Automattic\WooCommerce\Admin\Notes;
|
|
|
|
|
2019-03-12 13:13:20 +00:00
|
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
|
2019-08-12 21:52:09 +00:00
|
|
|
use \Automattic\WooCommerce\Admin\Install;
|
2019-08-12 17:54:04 +00:00
|
|
|
|
2019-03-12 13:13:20 +00:00
|
|
|
/**
|
2020-09-28 04:35:10 +00:00
|
|
|
* Historical_Data.
|
2019-03-12 13:13:20 +00:00
|
|
|
*/
|
2020-10-28 17:12:14 +00:00
|
|
|
class HistoricalData {
|
2020-05-22 13:48:40 +00:00
|
|
|
/**
|
|
|
|
* Note traits.
|
|
|
|
*/
|
|
|
|
use NoteTraits;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Name of the note for use in the database.
|
|
|
|
*/
|
2019-03-13 17:14:02 +00:00
|
|
|
const NOTE_NAME = 'wc-admin-historical-data';
|
2019-03-12 13:13:20 +00:00
|
|
|
|
2020-01-09 02:11:39 +00:00
|
|
|
/**
|
|
|
|
* Attach hooks.
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
|
|
|
add_action( 'woocommerce_analytics_regenerate_init', array( $this, 'update_status_to_actioned' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update status of note to actioned on data import trigger.
|
|
|
|
*/
|
|
|
|
public static function update_status_to_actioned() {
|
|
|
|
$data_store = \WC_Data_Store::load( 'admin-note' );
|
|
|
|
$note_ids = $data_store->get_notes_with_name( self::NOTE_NAME );
|
|
|
|
if ( empty( $note_ids ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-28 04:35:10 +00:00
|
|
|
$note = Notes::get_note( $note_ids[0] );
|
2020-07-20 18:28:00 +00:00
|
|
|
if ( false === $note ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-09 02:11:39 +00:00
|
|
|
$note->set_status( 'actioned' );
|
|
|
|
$note->save();
|
|
|
|
}
|
|
|
|
|
2019-03-12 13:13:20 +00:00
|
|
|
/**
|
2020-05-22 13:48:40 +00:00
|
|
|
* Get the note.
|
2020-09-28 04:35:10 +00:00
|
|
|
*
|
|
|
|
* @return Note
|
2019-03-12 13:13:20 +00:00
|
|
|
*/
|
2020-05-22 13:48:40 +00:00
|
|
|
public static function get_note() {
|
2019-08-12 21:52:09 +00:00
|
|
|
$is_upgrading = get_option( Install::VERSION_OPTION );
|
2019-04-01 02:25:53 +00:00
|
|
|
if ( $is_upgrading ) {
|
|
|
|
return;
|
|
|
|
}
|
2019-03-12 13:13:20 +00:00
|
|
|
|
2020-05-22 13:48:40 +00:00
|
|
|
// Only add this note if we don't have any orders.
|
|
|
|
$orders = wc_get_orders(
|
2019-04-01 02:25:53 +00:00
|
|
|
array(
|
|
|
|
'limit' => 1,
|
|
|
|
)
|
|
|
|
);
|
2020-05-22 13:48:40 +00:00
|
|
|
if ( count( $orders ) < 1 ) {
|
2019-03-12 13:13:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-28 04:35:10 +00:00
|
|
|
$note = new Note();
|
2019-03-13 17:14:02 +00:00
|
|
|
$note->set_title( __( 'WooCommerce Admin: Historical Analytics Data', 'woocommerce-admin' ) );
|
|
|
|
$note->set_content( __( 'To view your historical analytics data, you must process your existing orders and customers.', 'woocommerce-admin' ) );
|
2020-09-28 04:35:10 +00:00
|
|
|
$note->set_type( Note::E_WC_ADMIN_NOTE_UPDATE );
|
2019-03-12 13:13:20 +00:00
|
|
|
$note->set_name( self::NOTE_NAME );
|
|
|
|
$note->set_content_data( (object) array() );
|
|
|
|
$note->set_source( 'woocommerce-admin' );
|
2019-03-13 17:14:02 +00:00
|
|
|
// @todo Add remind me later option. See https://github.com/woocommerce/woocommerce-admin/issues/1756.
|
2019-03-12 13:13:20 +00:00
|
|
|
$note->add_action(
|
|
|
|
'get-started',
|
2019-03-13 17:14:02 +00:00
|
|
|
__( 'Get Started', 'woocommerce-admin' ),
|
2019-08-14 17:35:28 +00:00
|
|
|
'?page=wc-admin&path=/analytics/settings&import=true',
|
2019-05-21 19:01:55 +00:00
|
|
|
'actioned',
|
|
|
|
true
|
2019-03-12 13:13:20 +00:00
|
|
|
);
|
2020-05-22 13:48:40 +00:00
|
|
|
return $note;
|
2019-03-12 13:13:20 +00:00
|
|
|
}
|
|
|
|
}
|