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-coupon-data-store.php
63 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class WC_Order_Item_Coupon_Data_Store file. |
| 4 | * |
| 5 | * @package WooCommerce\DataStores |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * WC Order Item Coupon Data Store |
| 14 | * |
| 15 | * @version 3.0.0 |
| 16 | */ |
| 17 | class WC_Order_Item_Coupon_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( 'discount_amount', 'discount_amount_tax' ); |
| 26 | |
| 27 | /** |
| 28 | * Read/populate data properties specific to this order item. |
| 29 | * |
| 30 | * @since 3.0.0 |
| 31 | * @param WC_Order_Item_Coupon $item Coupon order item. |
| 32 | */ |
| 33 | public function read( &$item ) { |
| 34 | parent::read( $item ); |
| 35 | $id = $item->get_id(); |
| 36 | $item->set_props( |
| 37 | array( |
| 38 | 'discount' => get_metadata( 'order_item', $id, 'discount_amount', true ), |
| 39 | 'discount_tax' => get_metadata( 'order_item', $id, 'discount_amount_tax', true ), |
| 40 | ) |
| 41 | ); |
| 42 | $item->set_object_read( true ); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Saves an item's data to the database / item meta. |
| 47 | * Ran after both create and update, so $item->get_id() will be set. |
| 48 | * |
| 49 | * @since 3.0.0 |
| 50 | * @param WC_Order_Item_Coupon $item Coupon order item. |
| 51 | */ |
| 52 | public function save_item_data( &$item ) { |
| 53 | $id = $item->get_id(); |
| 54 | $save_values = array( |
| 55 | 'discount_amount' => $item->get_discount( 'edit' ), |
| 56 | 'discount_amount_tax' => $item->get_discount_tax( 'edit' ), |
| 57 | ); |
| 58 | foreach ( $save_values as $key => $value ) { |
| 59 | update_metadata( 'order_item', $id, $key, $value ); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 |