Automattic\WooCommerce\Admin\API
NoteActions::trigger_note_action
Trigger a note action.
Метод класса: NoteActions{}
Хуков нет.
Возвращает
WP_REST_Request|WP_Error.
Использование
$NoteActions = new NoteActions(); $NoteActions->trigger_note_action( $request );
- $request(WP_REST_Request) (обязательный)
- Full details about the request.
Код NoteActions::trigger_note_action() NoteActions::trigger note action WC 10.6.2
public function trigger_note_action( $request ) {
$note = NotesFactory::get_note( $request->get_param( 'note_id' ) );
if ( ! $note ) {
return new \WP_Error(
'woocommerce_note_invalid_id',
__( 'Sorry, there is no resource with that ID.', 'woocommerce' ),
array( 'status' => 404 )
);
}
$note->set_is_read( true );
$note->save();
$triggered_action = NotesFactory::get_action_by_id( $note, $request->get_param( 'action_id' ) );
if ( ! $triggered_action ) {
return new \WP_Error(
'woocommerce_note_action_invalid_id',
__( 'Sorry, there is no resource with that ID.', 'woocommerce' ),
array( 'status' => 404 )
);
}
$triggered_note = NotesFactory::trigger_note_action( $note, $triggered_action );
$data = $triggered_note->get_data();
$data = $this->prepare_item_for_response( $data, $request );
$data = $this->prepare_response_for_collection( $data );
return rest_ensure_response( $data );
}