Automattic\WooCommerce\Admin\Features\Fulfillments

FulfillmentOrderNotes::add_fulfillment_created_notepublicWC 1.0

Add an order note when a fulfillment is created.

Method of the class: FulfillmentOrderNotes{}

Returns

null. Nothing (null).

Usage

$FulfillmentOrderNotes = new FulfillmentOrderNotes();
$FulfillmentOrderNotes->add_fulfillment_created_note( $fulfillment ): void;
$fulfillment(Fulfillment) (required)
The fulfillment object.

FulfillmentOrderNotes::add_fulfillment_created_note() code WC 10.7.0

public function add_fulfillment_created_note( Fulfillment $fulfillment ): void {
	$order = $fulfillment->get_order();
	if ( ! $order instanceof \WC_Order ) {
		return;
	}

	$items_text    = $this->format_items( $fulfillment, $order );
	$tracking_text = $this->format_tracking( $fulfillment );
	$status        = $fulfillment->get_status() ?? 'unfulfilled';
	$status_label  = $this->get_fulfillment_status_label( $status );

	$message = sprintf(
		/* translators: 1: fulfillment ID, 2: fulfillment status label, 3: item list */
		__( 'Fulfillment #%1$d created (status: %2$s). Items: %3$s.', 'woocommerce' ),
		$fulfillment->get_id(),
		$status_label,
		$items_text
	);

	if ( ! empty( $tracking_text ) ) {
		$message .= ' ' . sprintf(
			/* translators: %s: tracking number */
			__( 'Tracking: %s.', 'woocommerce' ),
			$tracking_text
		);
	}

	/**
	 * Filters the order note message when a fulfillment is created.
	 *
	 * Return null to cancel the note.
	 *
	 * @since 10.7.0
	 *
	 * @param string|null  $message     The note message.
	 * @param Fulfillment  $fulfillment The fulfillment object.
	 * @param \WC_Order    $order       The order object.
	 */
	$message = apply_filters( 'woocommerce_fulfillment_created_order_note', $message, $fulfillment, $order );
	$message = $this->normalize_note_message( $message );

	if ( null === $message ) {
		return;
	}

	$order->add_order_note( $message, 0, false, array( 'note_group' => OrderNoteGroup::FULFILLMENT ) );
}