abstract-wc-order-data-store-cpt.php
5 years ago
abstract-wc-order-item-type-data-store.php
6 years ago
class-wc-coupon-data-store-cpt.php
5 years ago
class-wc-customer-data-store-session.php
7 years ago
class-wc-customer-data-store.php
5 years ago
class-wc-customer-download-data-store.php
6 years ago
class-wc-customer-download-log-data-store.php
6 years ago
class-wc-data-store-wp.php
5 years ago
class-wc-order-data-store-cpt.php
5 years ago
class-wc-order-item-coupon-data-store.php
8 years ago
class-wc-order-item-data-store.php
6 years ago
class-wc-order-item-fee-data-store.php
8 years ago
class-wc-order-item-product-data-store.php
8 years ago
class-wc-order-item-shipping-data-store.php
5 years ago
class-wc-order-item-tax-data-store.php
6 years ago
class-wc-order-refund-data-store-cpt.php
5 years ago
class-wc-payment-token-data-store.php
6 years ago
class-wc-product-data-store-cpt.php
5 years ago
class-wc-product-grouped-data-store-cpt.php
7 years ago
class-wc-product-variable-data-store-cpt.php
5 years ago
class-wc-product-variation-data-store-cpt.php
5 years ago
class-wc-shipping-zone-data-store.php
6 years ago
class-wc-webhook-data-store.php
5 years ago
class-wc-order-item-shipping-data-store.php
79 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WC Order Item Shipping Data Store |
| 4 | * |
| 5 | * @version 3.0.0 |
| 6 | * @package WooCommerce\DataStores |
| 7 | */ |
| 8 | |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit; |
| 11 | } |
| 12 | |
| 13 | /** |
| 14 | * WC_Order_Item_Shipping_Data_Store class. |
| 15 | */ |
| 16 | class WC_Order_Item_Shipping_Data_Store extends Abstract_WC_Order_Item_Type_Data_Store implements WC_Object_Data_Store_Interface, WC_Order_Item_Type_Data_Store_Interface { |
| 17 | |
| 18 | /** |
| 19 | * Data stored in meta keys. |
| 20 | * |
| 21 | * @since 3.0.0 |
| 22 | * @var array |
| 23 | */ |
| 24 | protected $internal_meta_keys = array( 'method_id', 'instance_id', 'cost', 'total_tax', 'taxes' ); |
| 25 | |
| 26 | /** |
| 27 | * Read/populate data properties specific to this order item. |
| 28 | * |
| 29 | * @since 3.0.0 |
| 30 | * @param WC_Order_Item_Shipping $item Item to read to. |
| 31 | * @throws Exception If invalid shipping order item. |
| 32 | */ |
| 33 | public function read( &$item ) { |
| 34 | parent::read( $item ); |
| 35 | $id = $item->get_id(); |
| 36 | $item->set_props( |
| 37 | array( |
| 38 | 'method_id' => get_metadata( 'order_item', $id, 'method_id', true ), |
| 39 | 'instance_id' => get_metadata( 'order_item', $id, 'instance_id', true ), |
| 40 | 'total' => get_metadata( 'order_item', $id, 'cost', true ), |
| 41 | 'taxes' => get_metadata( 'order_item', $id, 'taxes', true ), |
| 42 | ) |
| 43 | ); |
| 44 | |
| 45 | // BW compat. |
| 46 | if ( '' === $item->get_instance_id() && strstr( $item->get_method_id(), ':' ) ) { |
| 47 | $legacy_method_id = explode( ':', $item->get_method_id() ); |
| 48 | $item->set_method_id( $legacy_method_id[0] ); |
| 49 | $item->set_instance_id( $legacy_method_id[1] ); |
| 50 | } |
| 51 | |
| 52 | $item->set_object_read( true ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Saves an item's data to the database / item meta. |
| 57 | * Ran after both create and update, so $id will be set. |
| 58 | * |
| 59 | * @since 3.0.0 |
| 60 | * @param WC_Order_Item_Shipping $item Item to save. |
| 61 | */ |
| 62 | public function save_item_data( &$item ) { |
| 63 | $id = $item->get_id(); |
| 64 | $changes = $item->get_changes(); |
| 65 | $meta_key_to_props = array( |
| 66 | 'method_id' => 'method_id', |
| 67 | 'instance_id' => 'instance_id', |
| 68 | 'cost' => 'total', |
| 69 | 'total_tax' => 'total_tax', |
| 70 | 'taxes' => 'taxes', |
| 71 | ); |
| 72 | $props_to_update = $this->get_props_to_update( $item, $meta_key_to_props, 'order_item' ); |
| 73 | |
| 74 | foreach ( $props_to_update as $meta_key => $prop ) { |
| 75 | update_metadata( 'order_item', $id, $meta_key, $item->{"get_$prop"}( 'edit' ) ); |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 |