* Added new note type

This commit adds a new note type `survey`. The note is deleted after calling its CTA.

* Now using const from WC_Admin_Note

* Now using const from WC_Admin_Note in WC_Admin_Notes too

* Moved note deletion from NoteActions to WC_Admin_Notes

This commit moves the note deletion from NoteActions to WC_Admin_Notes. Also adds a hook to clean up actioned survey notes.

Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
This commit is contained in:
Fernando 2020-07-02 15:56:06 -03:00 committed by GitHub
parent 90089a5416
commit 7b1a485100
5 changed files with 32 additions and 4 deletions

View File

@ -22,5 +22,5 @@ export const QUERY_DEFAULTS = {
pageSize: 25,
period: 'month',
compare: 'previous_year',
noteTypes: 'info,warning,marketing',
noteTypes: 'info,warning,marketing,survey',
};

View File

@ -11,6 +11,7 @@ namespace Automattic\WooCommerce\Admin\API;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Admin\Notes\WC_Admin_Note;
use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes;
/**

View File

@ -22,6 +22,7 @@ class WC_Admin_Note extends \WC_Data {
const E_WC_ADMIN_NOTE_UPDATE = 'update'; // i.e. used when a new version is available.
const E_WC_ADMIN_NOTE_INFORMATIONAL = 'info'; // used for presenting informational messages.
const E_WC_ADMIN_NOTE_MARKETING = 'marketing'; // used for adding marketing messages.
const E_WC_ADMIN_NOTE_SURVEY = 'survey'; // used for adding survey messages.
// Note status codes.
const E_WC_ADMIN_NOTE_PENDING = 'pending'; // the note is pending - hidden but not actioned.
@ -126,6 +127,7 @@ class WC_Admin_Note extends \WC_Data {
self::E_WC_ADMIN_NOTE_UPDATE,
self::E_WC_ADMIN_NOTE_INFORMATIONAL,
self::E_WC_ADMIN_NOTE_MARKETING,
self::E_WC_ADMIN_NOTE_SURVEY,
);
return apply_filters( 'woocommerce_note_types', $allowed_types );

View File

@ -24,6 +24,7 @@ class WC_Admin_Notes {
*/
public static function init() {
add_action( 'admin_init', array( __CLASS__, 'schedule_unsnooze_notes' ) );
add_action( 'admin_init', array( __CLASS__, 'possibly_delete_survey_notes' ) );
add_action( 'update_option_woocommerce_show_marketplace_suggestions', array( __CLASS__, 'possibly_delete_marketing_notes' ), 10, 2 );
}
@ -164,7 +165,12 @@ class WC_Admin_Notes {
'orderby' => 'date_created',
'per_page' => 25,
'page' => 1,
'type' => array( 'info', 'marketing', 'warning' ),
'type' => array(
WC_Admin_Note::E_WC_ADMIN_NOTE_INFORMATIONAL,
WC_Admin_Note::E_WC_ADMIN_NOTE_MARKETING,
WC_Admin_Note::E_WC_ADMIN_NOTE_WARNING,
WC_Admin_Note::E_WC_ADMIN_NOTE_SURVEY,
),
'is_deleted' => 0,
)
);
@ -241,4 +247,23 @@ class WC_Admin_Notes {
$note->delete();
}
}
/**
* Delete actioned survey notes.
*/
public static function possibly_delete_survey_notes() {
$data_store = \WC_Data_Store::load( 'admin-note' );
$notes = $data_store->get_notes(
array(
'type' => array( WC_Admin_Note::E_WC_ADMIN_NOTE_SURVEY ),
'status' => array( 'actioned' ),
)
);
foreach ( $notes as $note ) {
$note = new WC_Admin_Note( $note->note_id );
$note->set_is_deleted( 1 );
$note->save();
}
}
}

View File

@ -35,9 +35,9 @@ class WC_Admin_Notes_Insight_First_Sale {
}
$note = new WC_Admin_Note();
$note->set_title( __( 'Insight', 'woocommerce-admin' ) );
$note->set_title( __( 'Did you know?', 'woocommerce-admin' ) );
$note->set_content( __( 'A WooCommerce powered store needs on average 31 days to get the first sale. You\'re on the right track! Do you find this type of insight useful?', 'woocommerce-admin' ) );
$note->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
$note->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_SURVEY );
$note->set_name( self::NOTE_NAME );
$note->set_content_data( (object) array() );
$note->set_source( 'woocommerce-admin' );