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.

Метод класса: WooSubscriptionsNotes{}

Хуков нет.

Возвращает

Note|false.

Использование

$WooSubscriptionsNotes = new WooSubscriptionsNotes();
$WooSubscriptionsNotes->find_note_for_product_id( $product_id );
$product_id(int) (обязательный)
The product ID to search for.

Код WooSubscriptionsNotes::find_note_for_product_id() WC 8.7.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;
}