PHP 8.2.31
Preview: RestockRefundedItemsAdjuster.php Size: 2.14 KB
/home/nshryvcy/radiantskinclinics.org/wp-content/plugins/woocommerce/src/Internal/RestockRefundedItemsAdjuster.php

<?php
/**
 * RestockRefundedItemsAdjuster class file.
 */

namespace Automattic\WooCommerce\Internal;

use Automattic\WooCommerce\Enums\OrderItemType;
use Automattic\WooCommerce\Proxies\LegacyProxy;

defined( 'ABSPATH' ) || exit;

/**
 * Class to adjust or initialize the restock refunded items.
 */
class RestockRefundedItemsAdjuster {
	/**
	 * The order factory to use.
	 *
	 * @var WC_Order_Factory
	 */
	private $order_factory;

	/**
	 * Class initialization, to be executed when the class is resolved by the container.
	 *
	 * @internal
	 */
	final public function init() {
		$this->order_factory = wc_get_container()->get( LegacyProxy::class )->get_instance_of( \WC_Order_Factory::class );
		add_action( 'woocommerce_before_save_order_items', array( $this, 'initialize_restock_refunded_items' ), 10, 2 );
	}

	/**
	 * Initializes the restock refunded items meta for order version less than 5.5.
	 *
	 * @see https://github.com/woocommerce/woocommerce/issues/29502
	 *
	 * @param int   $order_id Order ID.
	 * @param array $items Order items to save.
	 */
	public function initialize_restock_refunded_items( $order_id, $items ) {
		$order         = wc_get_order( $order_id );
		$order_version = $order->get_version();

		if ( version_compare( $order_version, '5.5', '>=' ) ) {
			return;
		}

		// If there are no refund lines, then this migration isn't necessary because restock related meta's wouldn't be set.
		if ( 0 === count( $order->get_refunds() ) ) {
			return;
		}

		if ( isset( $items['order_item_id'] ) ) {
			foreach ( $items['order_item_id'] as $item_id ) {
				$item = $this->order_factory::get_order_item( absint( $item_id ) );

				if ( ! $item ) {
					continue;
				}

				if ( OrderItemType::LINE_ITEM !== $item->get_type() ) {
					continue;
				}

				// There could be code paths in custom code which don't update version number but still update the items.
				if ( '' !== $item->get_meta( '_restock_refunded_items', true ) ) {
					continue;
				}

				$refunded_item_quantity = abs( $order->get_qty_refunded_for_item( $item->get_id() ) );
				$item->add_meta_data( '_restock_refunded_items', $refunded_item_quantity, false );
				$item->save();
			}
		}
	}
}

Directory Contents

Dirs: 37 × Files: 9

Name Size Perms Modified Actions
Abilities DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Admin DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Agentic DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Api DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Caches DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
CLI DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Customers DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Email DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Features DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Jetpack DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Logging DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
MCP DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Orders DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
RestApi DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Settings DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Traits DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Utilities DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
WCCom DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
1.95 KB lrw-r--r-- 2024-08-27 23:04:44
Edit Download
1.27 KB lrw-r--r-- 2025-07-29 12:34:58
Edit Download
6.60 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
2.10 KB lrw-r--r-- 2024-09-23 20:44:04
Edit Download
8.33 KB lrw-r--r-- 2024-12-18 22:19:16
Edit Download
504 B lrw-r--r-- 2024-11-28 03:41:18
Edit Download
8.01 KB lrw-r--r-- 2025-06-23 19:46:28
Edit Download
5.72 KB lrw-r--r-- 2024-05-28 14:28:20
Edit Download
2.14 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).