Automattic\WooCommerce\Admin\Features\Fulfillments

FulfillmentOrderNotes::add_fulfillment_status_changed_noteprivateWC 1.0

Add a status change note for a fulfillment.

Method of the class: FulfillmentOrderNotes{}

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->add_fulfillment_status_changed_note( $fulfillment, $order, $old_status, $new_status ): void;
$fulfillment(Fulfillment) (required)
The fulfillment object.
$order(WC_Order) (required)
The order object.
$old_status(string) (required)
The previous status.
$new_status(string) (required)
The new status.

FulfillmentOrderNotes::add_fulfillment_status_changed_note() code WC 10.7.0

private function add_fulfillment_status_changed_note( Fulfillment $fulfillment, \WC_Order $order, string $old_status, string $new_status ): void {
	$old_status_label = $this->get_fulfillment_status_label( $old_status );
	$new_status_label = $this->get_fulfillment_status_label( $new_status );

	$message = sprintf(
		/* translators: 1: fulfillment ID, 2: old status label, 3: new status label */
		__( 'Fulfillment #%1$d status changed from %2$s to %3$s.', 'woocommerce' ),
		$fulfillment->get_id(),
		$old_status_label,
		$new_status_label
	);

	/**
	 * Filters the order note message when a fulfillment status changes.
	 *
	 * 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.
	 * @param string       $old_status  The previous status.
	 * @param string       $new_status  The new status.
	 */
	$message = apply_filters( 'woocommerce_fulfillment_status_changed_order_note', $message, $fulfillment, $order, $old_status, $new_status );
	$message = $this->normalize_note_message( $message );

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

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