Automattic\WooCommerce\Admin\Features\Fulfillments
FulfillmentOrderNotes::add_fulfillment_updated_note
Add an order note when a fulfillment is updated.
Only adds a note when tracked properties change (status, items, tracking number, tracking URL, shipping provider). If the status changed, a dedicated status change note is added instead.
Method of the class: FulfillmentOrderNotes{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$FulfillmentOrderNotes = new FulfillmentOrderNotes(); $FulfillmentOrderNotes->add_fulfillment_updated_note( $fulfillment, $changes, $previous_status ): void;
- $fulfillment(Fulfillment) (required)
- The fulfillment object (post-update).
- $changes(array)
- Changes as returned by Fulfillment::get_changes() before save. Core data props at top level, meta under
'meta_data'.
Default:array() - $previous_status(string)
- The fulfillment status before the update.
Default:'unfulfilled'
FulfillmentOrderNotes::add_fulfillment_updated_note() FulfillmentOrderNotes::add fulfillment updated note code WC 10.7.0
public function add_fulfillment_updated_note( Fulfillment $fulfillment, array $changes = array(), string $previous_status = 'unfulfilled' ): void {
if ( empty( $changes ) ) {
return;
}
$order = $fulfillment->get_order();
if ( ! $order instanceof \WC_Order ) {
return;
}
// If status changed, add a dedicated status change note.
if ( array_key_exists( 'status', $changes ) ) {
$new_status = $changes['status'] ?? 'unfulfilled';
$this->add_fulfillment_status_changed_note( $fulfillment, $order, $previous_status, $new_status );
return;
}
$items_text = $this->format_items( $fulfillment, $order );
$tracking_text = $this->format_tracking( $fulfillment );
$message = sprintf(
/* translators: 1: fulfillment ID, 2: item list */
__( 'Fulfillment #%1$d updated. Items: %2$s.', 'woocommerce' ),
$fulfillment->get_id(),
$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 updated.
*
* 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_updated_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 ) );
}