LLMS_Order::add_note( string $note, boolean $added_by_user = false )

Add an admin-only note to the order visible on the admin panel notes are recorded using the wp comments API & DB


Parameters Parameters

$note

(string) (Required) Note content.

$added_by_user

(boolean) (Optional) If this is an admin-submitted note adds user info to note meta. Default is false.

Default value: false


Top ↑

Return Return

(null|int) Null on error or WP_Comment ID of the note.


Top ↑

Source Source

File: includes/models/model.llms.order.php

	public function add_note( $note, $added_by_user = false ) {

		if ( ! $note ) {
			return;
		}

		// Added by a user from the admin panel.
		if ( $added_by_user && is_user_logged_in() && current_user_can( apply_filters( 'lifterlms_admin_order_access', 'manage_options' ) ) ) {

			$user_id      = get_current_user_id();
			$user         = get_user_by( 'id', $user_id );
			$author       = $user->display_name;
			$author_email = $user->user_email;

		} else {

			$user_id       = 0;
			$author        = _x( 'LifterLMS', 'default order note author', 'lifterlms' );
			$author_email  = strtolower( _x( 'LifterLms', 'default order note author', 'lifterlms' ) ) . '@';
			$author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) ) : 'noreply.com';
			$author_email  = sanitize_email( $author_email );

		}

		$note_id = wp_insert_comment(
			apply_filters(
				'llms_add_order_note_content',
				array(
					'comment_post_ID'      => $this->get( 'id' ),
					'comment_author'       => $author,
					'comment_author_email' => $author_email,
					'comment_author_url'   => '',
					'comment_content'      => $note,
					'comment_type'         => 'llms_order_note',
					'comment_parent'       => 0,
					'user_id'              => $user_id,
					'comment_approved'     => 1,
					'comment_agent'        => 'LifterLMS',
					'comment_date'         => current_time( 'mysql' ),
				)
			)
		);

		do_action( 'llms_new_order_note_added', $note_id, $this );

		return $note_id;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
3.35.0 Sanitize $_SERVER data.
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.