logger = $logger; } /** * Handle a newly added order note. * * @param int $note_id Comment id of the note. * @param \WC_Order $order Order the note belongs to. */ public function on_note_added( $note_id, $order ) { $mode = Options::notes_mode(); if ( 'off' === $mode ) { return; } if ( '' === Options::token() ) { return; } $comment = get_comment( $note_id ); if ( ! $comment ) { return; } // Only human-added notes. System/programmatic notes (status changes, our // own audit notes) use the 'WooCommerce' author and must be ignored to // avoid loops and noise. if ( 'WooCommerce' === $comment->comment_author ) { return; } $is_customer_note = (bool) get_comment_meta( $note_id, 'is_customer_note', true ); if ( 'customer' === $mode && ! $is_customer_note ) { return; } if ( ! $order instanceof \WC_Order ) { $order = wc_get_order( $order ); } if ( ! $order ) { return; } if ( Options::optout_enabled() && ! OptOut::is_allowed( $order ) ) { return; } // No 'attempt' — retries reuse identical args (dedup); counter in comment meta. $payload = array( 'kind' => 'note', 'order_id' => $order->get_id(), 'note_id' => (int) $note_id, ); if ( ! function_exists( 'as_enqueue_async_action' ) ) { do_action( SENDLY_HOOK, $payload ); return; } if ( function_exists( 'as_has_scheduled_action' ) && as_has_scheduled_action( SENDLY_HOOK, array( $payload ), SENDLY_GROUP ) ) { return; } as_enqueue_async_action( SENDLY_HOOK, array( $payload ), SENDLY_GROUP ); } }