__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
<?php
/**
* RestockRefundedItemsAdjuster class file.
*/
namespace Automattic\WooCommerce\Internal;
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 ( '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();
}
}
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| Abilities | Folder | 0775 |
|
|
| AbilitiesApi | Folder | 0775 |
|
|
| AddressProvider | Folder | 0775 |
|
|
| Admin | Folder | 0775 |
|
|
| Agentic | Folder | 0775 |
|
|
| BatchProcessing | Folder | 0775 |
|
|
| CLI | Folder | 0775 |
|
|
| Caches | Folder | 0775 |
|
|
| ComingSoon | Folder | 0775 |
|
|
| CostOfGoodsSold | Folder | 0775 |
|
|
| Customers | Folder | 0775 |
|
|
| DataStores | Folder | 0775 |
|
|
| DependencyManagement | Folder | 0775 |
|
|
| Folder | 0775 |
|
||
| EmailEditor | Folder | 0775 |
|
|
| Features | Folder | 0775 |
|
|
| Font | Folder | 0775 |
|
|
| Fulfillments | Folder | 0775 |
|
|
| Integrations | Folder | 0775 |
|
|
| Logging | Folder | 0775 |
|
|
| MCP | Folder | 0775 |
|
|
| Orders | Folder | 0775 |
|
|
| ProductAttributesLookup | Folder | 0775 |
|
|
| ProductDownloads | Folder | 0775 |
|
|
| ProductFilters | Folder | 0775 |
|
|
| ProductImage | Folder | 0775 |
|
|
| PushNotifications | Folder | 0775 |
|
|
| ReceiptRendering | Folder | 0775 |
|
|
| RestApi | Folder | 0775 |
|
|
| Settings | Folder | 0775 |
|
|
| StockNotifications | Folder | 0775 |
|
|
| Traits | Folder | 0775 |
|
|
| TransientFiles | Folder | 0775 |
|
|
| Utilities | Folder | 0775 |
|
|
| WCCom | Folder | 0775 |
|
|
| AssignDefaultCategory.php | File | 1.95 KB | 0664 |
|
| Brands.php | File | 1.27 KB | 0664 |
|
| DownloadPermissionsAdjuster.php | File | 6.52 KB | 0664 |
|
| McStats.php | File | 2.1 KB | 0664 |
|
| OrderCouponDataMigrator.php | File | 8.33 KB | 0664 |
|
| RegisterHooksInterface.php | File | 504 B | 0664 |
|
| RestApiControllerBase.php | File | 8.01 KB | 0664 |
|
| RestApiParameterUtil.php | File | 5.72 KB | 0664 |
|
| RestockRefundedItemsAdjuster.php | File | 2.08 KB | 0664 |
|