Automattic\WooCommerce\Admin\API
Notes::activate_promo_note()
Activate a promo note, create if not exist.
Method of the class: Notes{}
Hooks from the method
Return
WP_REST_Request|WP_Error
.
Usage
$Notes = new Notes(); $Notes->activate_promo_note( $request );
- $request(WP_REST_Request) (required)
- Request object.
Notes::activate_promo_note() Notes::activate promo note code WC 9.7.1
public function activate_promo_note( $request ) { /** * Filter allowed promo notes for experimental-activate-promo. * * @param array $promo_notes Array of allowed promo notes. * @since 7.8.0 */ $allowed_promo_notes = apply_filters( 'woocommerce_admin_allowed_promo_notes', [] ); $promo_note_name = $request->get_param( 'promo_note_name' ); if ( ! in_array( $promo_note_name, $allowed_promo_notes, true ) ) { return new \WP_Error( 'woocommerce_note_invalid_promo_note_name', __( 'Please provide a valid promo note name.', 'woocommerce' ), array( 'status' => 422 ) ); } $data_store = NotesRepository::load_data_store(); $note_ids = $data_store->get_notes_with_name( $promo_note_name ); if ( empty( $note_ids ) ) { // Promo note doesn't exist, this could happen in cases where // user might have disabled RemoteInboxNotications via disabling // marketing suggestions. Thus we'd have to manually add the note. $note = new Note(); $note->set_name( $promo_note_name ); $note->set_status( Note::E_WC_ADMIN_NOTE_ACTIONED ); $data_store->create( $note ); } else { $note = NotesRepository::get_note( $note_ids[0] ); NotesRepository::update_note( $note, [ 'status' => Note::E_WC_ADMIN_NOTE_ACTIONED, ] ); } return rest_ensure_response( array( 'success' => true, ) ); }