Automattic\WooCommerce\Internal\Admin\Notes

WooSubscriptionsNotes::find_note_for_product_id()publicWC 1.0

Finds a note for a given product ID, if the note exists at all.

{} It's a method of the class: WooSubscriptionsNotes{}

No Hooks.

Return

Note|false.

Usage

$WooSubscriptionsNotes = new WooSubscriptionsNotes();
$WooSubscriptionsNotes->find_note_for_product_id( $product_id );
$product_id(int) (required)
The product ID to search for.

Code of WooSubscriptionsNotes::find_note_for_product_id() WC 7.1.0

public function find_note_for_product_id( $product_id ) {
	$product_id = intval( $product_id );

	$data_store = Notes::load_data_store();
	$note_ids   = $data_store->get_notes_with_name( self::SUBSCRIPTION_NOTE_NAME );
	foreach ( (array) $note_ids as $note_id ) {
		$note             = Notes::get_note( $note_id );
		$found_product_id = $this->get_product_id_from_subscription_note( $note );

		if ( $product_id === $found_product_id ) {
			return $note;
		}
	}

	return false;
}