Commit 469d7d71b1 for woocommerce

commit 469d7d71b189f2b02bdc68e1e8e198bc8cd95287
Author: Boro Sitnikovski <buritomath@gmail.com>
Date:   Fri Jan 16 18:05:09 2026 +0100

    Add conditional checks before calling `WC_Logger_Interface::clear` (#62637)

    * Add clear method to WC_Logger_Interface

    The clear() method was already implemented in WC_Logger but was missing
    from the WC_Logger_Interface. This caused fatal errors when custom logger
    implementations that rely on the interface contract are used, as they
    don't implement the clear() method that core code expects to call.

    * Lint

    * Rather than adding the method to the interface, add conditional checks around it

    Props @jorgeatorres

    * Lint

    * Change instanceof check to WC_Logger, per discussions

    * Update changelog

    * Changelog grammar

    * Remove is_callable checks, props @jorgeatorres

diff --git a/plugins/woocommerce/changelog/tweak-add-checks-to-clear-method-logger-interface b/plugins/woocommerce/changelog/tweak-add-checks-to-clear-method-logger-interface
new file mode 100644
index 0000000000..92d0e17aab
--- /dev/null
+++ b/plugins/woocommerce/changelog/tweak-add-checks-to-clear-method-logger-interface
@@ -0,0 +1,4 @@
+Significance: minor
+Type: tweak
+
+Add instanceof/is_callable checks to the `clear` method of `WC_Logger`
diff --git a/plugins/woocommerce/includes/class-wc-logger.php b/plugins/woocommerce/includes/class-wc-logger.php
index efa39f6e5a..9b24140c3b 100644
--- a/plugins/woocommerce/includes/class-wc-logger.php
+++ b/plugins/woocommerce/includes/class-wc-logger.php
@@ -324,7 +324,7 @@ class WC_Logger implements WC_Logger_Interface {
 		}

 		foreach ( $this->get_handlers() as $handler ) {
-			if ( is_callable( array( $handler, 'clear' ) ) ) {
+			if ( $handler instanceof WC_Log_Handler && is_callable( array( $handler, 'clear' ) ) ) {
 				$handler->clear( $source, $quiet );
 			}
 		}
diff --git a/plugins/woocommerce/includes/gateways/paypal/class-wc-gateway-paypal.php b/plugins/woocommerce/includes/gateways/paypal/class-wc-gateway-paypal.php
index 0a72cd585b..5488f67047 100644
--- a/plugins/woocommerce/includes/gateways/paypal/class-wc-gateway-paypal.php
+++ b/plugins/woocommerce/includes/gateways/paypal/class-wc-gateway-paypal.php
@@ -395,7 +395,9 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
 			if ( empty( self::$log ) ) {
 				self::$log = wc_get_logger();
 			}
-			self::$log->clear( self::ID );
+			if ( self::$log instanceof WC_Logger ) {
+				self::$log->clear( self::ID );
+			}
 		}

 		// Trigger Transact onboarding when settings are saved.
diff --git a/plugins/woocommerce/includes/wc-order-step-logger-functions.php b/plugins/woocommerce/includes/wc-order-step-logger-functions.php
index 76663496a7..444d54a6e7 100644
--- a/plugins/woocommerce/includes/wc-order-step-logger-functions.php
+++ b/plugins/woocommerce/includes/wc-order-step-logger-functions.php
@@ -87,7 +87,9 @@ function wc_log_order_step( string $message, ?array $context = null, bool $final
 			if ( $order && ( count( array_unique( $steps ) ) === count( $steps ) ) ) {
 				$order->delete_meta_data( '_debug_log_source' );
 				if ( OrderUtil::unknown_orders_data_store_in_use() ) {
-					$logger->clear( $context['source'] );
+					if ( $logger instanceof WC_Logger ) {
+						$logger->clear( $context['source'] );
+					}
 					$order->save();
 				} else {
 					$order->add_meta_data( '_debug_log_source_pending_deletion', $context['source'], true );
diff --git a/plugins/woocommerce/src/Internal/Logging/OrderLogsDeletionProcessor.php b/plugins/woocommerce/src/Internal/Logging/OrderLogsDeletionProcessor.php
index 5f8666772f..175634fd0a 100644
--- a/plugins/woocommerce/src/Internal/Logging/OrderLogsDeletionProcessor.php
+++ b/plugins/woocommerce/src/Internal/Logging/OrderLogsDeletionProcessor.php
@@ -240,7 +240,9 @@ class OrderLogsDeletionProcessor implements BatchProcessorInterface {
 			if ( ! is_array( $item ) || ! isset( $item['meta_value'] ) || ! isset( $item['order_id'] ) ) {
 				throw new \Exception( "\$batch must be an array of arrays, each having a 'meta_value' key and an 'order_id' key" );
 			}
-			$logger->clear( $item['meta_value'] );
+			if ( $logger instanceof \WC_Logger ) {
+				$logger->clear( $item['meta_value'] );
+			}
 		}

 		$order_ids = array_map( 'absint', array_column( $batch, 'order_id' ) );
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/util/dummy-wc-logger.php b/plugins/woocommerce/tests/legacy/unit-tests/util/dummy-wc-logger.php
index 457545eb3b..23784d66c3 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/util/dummy-wc-logger.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/util/dummy-wc-logger.php
@@ -100,4 +100,15 @@ class Dummy_WC_Logger implements WC_Logger_Interface {
 	public function debug( $message, $context = array() ) {
 	}

+	/**
+	 * Do nothing.
+	 *
+	 * @param string $source Source.
+	 * @param bool   $quiet Quiet.
+	 *
+	 * @return bool
+	 */
+	public function clear( $source = '', $quiet = false ) {
+		return true;
+	}
 }