$this->error( 'admin_note_invalid_data', __( 'The admin note content_data prop must be an instance of stdClass.', 'woocommerce' ) );
$this->set_prop( 'content_data', $content_data );
* @param string $status Note status.
public function set_status( $status ) {
if ( empty( $status ) ) {
$this->error( 'admin_note_invalid_data', __( 'The admin note status prop cannot be empty.', 'woocommerce' ) );
if ( ! in_array( $status, self::get_allowed_statuses(), true ) ) {
'admin_note_invalid_data',
/* translators: %s: admin note status property. */
__( 'The admin note status prop (%s) is not one of the supported statuses.', 'woocommerce' ),
$this->set_prop( 'status', $status );
* @param string $source Note source.
public function set_source( $source ) {
if ( empty( $source ) ) {
$this->error( 'admin_note_invalid_data', __( 'The admin note source prop cannot be empty.', 'woocommerce' ) );
$this->set_prop( 'source', $source );
* Set date note was created. NULL is not allowed
* @param string|integer $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed.
public function set_date_created( $date ) {
$this->error( 'admin_note_invalid_data', __( 'The admin note date prop cannot be empty.', 'woocommerce' ) );
if ( is_string( $date ) && ! is_numeric( $date ) ) {
$date = wc_string_to_timestamp( $date );
$this->set_date_prop( 'date_created', $date );
* Set date admin should be reminded of note. NULL IS allowed
* @param string|integer|null $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if there is no date.
public function set_date_reminder( $date ) {
if ( is_string( $date ) && ! is_numeric( $date ) ) {
$date = wc_string_to_timestamp( $date );
$this->set_date_prop( 'date_reminder', $date );
* @param bool $is_snoozable Whether or not the note can be snoozed.
public function set_is_snoozable( $is_snoozable ) {
return $this->set_prop( 'is_snoozable', $is_snoozable );
* Clear actions from a note.
public function clear_actions() {
$this->set_prop( 'actions', array() );
* @param string $layout Note layout.
public function set_layout( $layout ) {
// If we don't receive a layout we will set it by default as "plain".
if ( empty( $layout ) ) {
$valid_layouts = array( 'plain', 'thumbnail' );
if ( in_array( $layout, $valid_layouts, true ) ) {
$this->set_prop( 'layout', $layout );
$this->error( 'admin_note_invalid_data', __( 'The admin note layout has a wrong prop value.', 'woocommerce' ) );
* @param string $image Note image.
public function set_image( $image ) {
$this->set_prop( 'image', $image );
* Set note deleted status. NULL is not allowed
* @param bool $is_deleted Note deleted status.
public function set_is_deleted( $is_deleted ) {
$this->set_prop( 'is_deleted', $is_deleted );
* Set note is_read status. NULL is not allowed
* @param bool $is_read Note is_read status.
public function set_is_read( $is_read ) {
$this->set_prop( 'is_read', $is_read );
* Add an action to the note
* @param string $name Action name (not presented to user).
* @param string $label Action label (presented as button label).
* @param string $url Action URL, if navigation needed. Optional.
* @param string $status Status to transition parent Note to upon click. Defaults to 'actioned'.
* @param boolean $primary Deprecated since version 3.4.0.
* @param string $actioned_text The label to display after the note has been actioned but before it is dismissed in the UI.
public function add_action(
$status = self::E_WC_ADMIN_NOTE_ACTIONED,
$name = wc_clean( $name );
$label = wc_clean( $label );
$query = esc_url_raw( $url );
$status = wc_clean( $status );
$actioned_text = wc_clean( $actioned_text );
$this->error( 'admin_note_invalid_data', __( 'The admin note action name prop cannot be empty.', 'woocommerce' ) );
$this->error( 'admin_note_invalid_data', __( 'The admin note action label prop cannot be empty.', 'woocommerce' ) );
'actioned_text' => $actioned_text,
$note_actions = $this->get_prop( 'actions', 'edit' );
$note_actions[] = (object) $action;
$this->set_prop( 'actions', $note_actions );
* @param array $actions Note actions.
public function set_actions( $actions ) {
$this->set_prop( 'actions', $actions );
* Add a nonce to an existing note action.
* @link https://codex.wordpress.org/WordPress_Nonces
* @param string $note_action_name Name of action to add a nonce to.
* @param string $nonce_action The nonce action.
* @param string $nonce_name The nonce Name. This is used as the parameter name in the resulting URL for the action.
* @throws \Exception If note name cannot be found.
public function add_nonce_to_action( string $note_action_name, string $nonce_action, string $nonce_name ) {
$actions = $this->get_prop( 'actions', 'edit' );
foreach ( $actions as $i => $action ) {
if ( $action->name === $note_action_name ) {
$matching_action =& $actions[ $i ];
if ( empty( $matching_action ) ) {
throw new \Exception( sprintf( 'Could not find action %s in note %s', $note_action_name, $this->get_name() ) );
$matching_action->nonce_action = $nonce_action;
$matching_action->nonce_name = $nonce_name;
$this->set_actions( $actions );