Commit 97b329aefa9 for woocommerce

commit 97b329aefa9a1ad9e2a0dd87802577e564b2271e
Author: Luis Felipe Zaguini <26530524+zaguiini@users.noreply.github.com>
Date:   Thu Nov 26 14:21:25 2026 -0300

    Fire woocommerce_payment_complete and woocommerce_order_after_calculate_totals through literal do_action() calls (#71476)

    * Fire the payment and totals hooks through literal do_action() calls

    The stage code deferred woocommerce_payment_complete and
    woocommerce_order_after_calculate_totals by passing 'do_action' and the
    hook name as data. The code reference, the phpcs hook comment sniff and
    the PHPStan hook docblock rule only find literal calls, so they lost
    both hooks. Each deferred entry is now a closure that holds the literal
    call and its docblock. The key, the arguments and the moment the hook
    fires stay the same.

    Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

    * Correct the since tags of woocommerce_payment_complete and the note about staged IDs

    Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

    ---------

    Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>

diff --git a/plugins/woocommerce/changelog/wooai-1852-literal-hook-calls b/plugins/woocommerce/changelog/wooai-1852-literal-hook-calls
new file mode 100644
index 00000000000..6bdd9525754
--- /dev/null
+++ b/plugins/woocommerce/changelog/wooai-1852-literal-hook-calls
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+Comment: Fire two order hooks through literal calls again so docs and lint find them; no behavior change.
+
diff --git a/plugins/woocommerce/includes/abstracts/abstract-wc-order.php b/plugins/woocommerce/includes/abstracts/abstract-wc-order.php
index ea230bf51ab..d302d4c2ae6 100644
--- a/plugins/woocommerce/includes/abstracts/abstract-wc-order.php
+++ b/plugins/woocommerce/includes/abstracts/abstract-wc-order.php
@@ -3334,15 +3334,18 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
 			$this->calculate_cogs_total_value();
 		}

-		/**
-		 * Fires after the order totals are calculated.
-		 *
-		 * @param bool              $and_taxes Whether the taxes were calculated too.
-		 * @param WC_Abstract_Order $order     Order object.
-		 * @param bool              $staged    Whether the totals were staged and are not yet saved. Always passed; a listener that wants it declares it with a default. When true, the order and its tax items are in memory and have no IDs yet; use the $order object, not the database. @since 11.4.0
-		 * @since 3.3.0
-		 */
-		$this->write_or_defer( 'after_calculate_totals', 'do_action', array( 'woocommerce_order_after_calculate_totals', $and_taxes, $this, ! $this->writing_through ) );
+		$after_calculate_totals = static function ( $and_taxes, $order, $staged ) {
+			/**
+			 * Fires after the order totals are calculated.
+			 *
+			 * @param bool              $and_taxes Whether the taxes were calculated too.
+			 * @param WC_Abstract_Order $order     Order object.
+			 * @param bool              $staged    Whether the totals were staged and are not yet saved. Always passed; a listener that wants it declares it with a default. When true, read the pending changes from $order, not from the database; only new items may still be waiting for an ID. @since 11.4.0
+			 * @since 3.3.0
+			 */
+			do_action( 'woocommerce_order_after_calculate_totals', $and_taxes, $order, $staged );
+		};
+		$this->write_or_defer( 'after_calculate_totals', $after_calculate_totals, array( $and_taxes, $this, ! $this->writing_through ) );

 		$this->save_if_writing_through();

diff --git a/plugins/woocommerce/includes/class-wc-order.php b/plugins/woocommerce/includes/class-wc-order.php
index 48a5b657574..6052a80a959 100644
--- a/plugins/woocommerce/includes/class-wc-order.php
+++ b/plugins/woocommerce/includes/class-wc-order.php
@@ -281,7 +281,7 @@ class WC_Order extends WC_Abstract_Order {

 		$this->save_if_writing_through();

-		$add_note    = function () use ( $payment_complete_note ) {
+		$add_note = function () use ( $payment_complete_note ) {
 			try {
 				$this->add_order_note( $payment_complete_note, 0, false, array( 'note_group' => OrderNoteGroup::PAYMENT ) );
 			} catch ( Exception $e ) {
@@ -294,19 +294,31 @@ class WC_Order extends WC_Abstract_Order {
 				);
 			}
 		};
-		$action_args = array( 'woocommerce_payment_complete', $this->get_id(), $transaction_id );
-		$save_error  = $this->writing_through ? $this->get_last_save_error() : null;
+
+		$order_id         = $this->get_id();
+		$payment_complete = static function () use ( $order_id, $transaction_id ) {
+			/**
+			 * Fires after the payment of an order is completed and the order is saved.
+			 *
+			 * @param int    $order_id       Order ID.
+			 * @param string $transaction_id Transaction ID of the order.
+			 * @since 1.2.2
+			 * @since 6.8.0 Passes $transaction_id.
+			 */
+			do_action( 'woocommerce_payment_complete', $order_id, $transaction_id );
+		};
+		$save_error       = $this->writing_through ? $this->get_last_save_error() : null;
 		if ( null !== $save_error ) {
 			$paid_status = $this->get_status();
 			$this->defer_to_save(
 				'payment_complete',
-				function () use ( $paid_status, $add_note, $action_args ) {
+				function () use ( $paid_status, $add_note, $payment_complete ) {
 					if ( ! $this->has_status( $paid_status ) && ! $this->is_paid() ) {
 						return;
 					}
 					$add_note();
 					try {
-						call_user_func_array( 'do_action', $action_args );
+						$payment_complete();
 					} catch ( Exception $e ) {
 						wc_get_logger()->error(
 							sprintf( 'Error completing payment for order #%d', $this->get_id() ),
@@ -324,7 +336,7 @@ class WC_Order extends WC_Abstract_Order {
 			throw $save_error;
 		}
 		$this->write_or_defer( 'payment_complete_note', $add_note, array(), true );
-		$this->write_or_defer( 'payment_complete', 'do_action', $action_args, true );
+		$this->write_or_defer( 'payment_complete', $payment_complete, array(), true );

 		return true;
 	}