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