ArrayUtil.php
7 months ago
BlocksUtil.php
5 months ago
COTMigrationUtil.php
4 days ago
DatabaseUtil.php
1 year ago
FilesystemUtil.php
4 days ago
HtmlSanitizer.php
2 years ago
LegacyRestApiStub.php
1 month ago
OrderItemMetaUtil.php
4 days ago
PluginInstaller.php
1 year ago
ProductUtil.php
4 days ago
Types.php
1 year ago
URL.php
1 year ago
URLException.php
4 years ago
Users.php
4 months ago
WebhookUtil.php
1 month ago
OrderItemMetaUtil.php
63 lines
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | |
| 4 | namespace Automattic\WooCommerce\Internal\Utilities; |
| 5 | |
| 6 | use WC_Order_Item; |
| 7 | |
| 8 | defined( 'ABSPATH' ) || exit; |
| 9 | |
| 10 | /** |
| 11 | * Helpers for the order item meta keys WooCommerce manages internally. |
| 12 | * |
| 13 | * @since 11.0.0 |
| 14 | */ |
| 15 | final class OrderItemMetaUtil { |
| 16 | |
| 17 | /** |
| 18 | * Get the order item meta keys hidden from the admin order screen. |
| 19 | * |
| 20 | * @return string[] |
| 21 | */ |
| 22 | public static function get_hidden_keys(): array { |
| 23 | /** |
| 24 | * Filters the order item meta keys hidden from the admin order screen. |
| 25 | * |
| 26 | * @since 2.2.0 |
| 27 | * @param string[] $hidden_keys Hidden order item meta keys. |
| 28 | */ |
| 29 | return apply_filters( |
| 30 | 'woocommerce_hidden_order_itemmeta', |
| 31 | array( |
| 32 | '_qty', |
| 33 | '_tax_class', |
| 34 | '_product_id', |
| 35 | '_variation_id', |
| 36 | '_line_subtotal', |
| 37 | '_line_subtotal_tax', |
| 38 | '_line_total', |
| 39 | '_line_tax', |
| 40 | 'method_id', |
| 41 | 'cost', |
| 42 | '_reduced_stock', |
| 43 | '_restock_refunded_items', |
| 44 | ) |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Get the meta keys that cannot be added or edited as custom meta on an order item. |
| 50 | * |
| 51 | * Combines the hidden keys with the item's own internal meta keys, which back core item data. |
| 52 | * |
| 53 | * @param WC_Order_Item $item Order item to check. |
| 54 | * @return string[] |
| 55 | */ |
| 56 | public static function get_reserved_keys( WC_Order_Item $item ): array { |
| 57 | // @phpstan-ignore-next-line method.notFound Proxied via WC_Data_Store::__call() on the order item data store. |
| 58 | $internal_meta_keys = (array) $item->get_data_store()->get_internal_meta_keys(); |
| 59 | |
| 60 | return array_values( array_unique( array_merge( self::get_hidden_keys(), $internal_meta_keys ) ) ); |
| 61 | } |
| 62 | } |
| 63 |