| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | if ( ! defined( 'ABSPATH' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | 	exit; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * Order Line Item (tax). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @version     2.7.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @since       2.7.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @package     WooCommerce/Classes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @author      WooThemes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | class WC_Order_Item_Tax extends WC_Order_Item { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 	 * Data properties of this order item object. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 	 * @since 2.7.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	 * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 	protected $_data = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 		'order_id'           => 0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 		'order_item_id'      => 0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 		'rate_code'          => '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 		'rate_id'            => 0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 		'label'              => '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 		'compound'           => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 		'tax_total'          => 0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 		'shipping_tax_total' => 0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 	 * Read/populate data properties specific to this order item. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	public function read( $id ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 		parent::read( $id ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 		if ( $this->get_id() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 			$this->set_rate_id( get_metadata( 'order_item', $this->get_id(), 'rate_id', true ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 			$this->set_label( get_metadata( 'order_item', $this->get_id(), 'label', true ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 			$this->set_compound( get_metadata( 'order_item', $this->get_id(), 'compound', true ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 			$this->set_tax_total( get_metadata( 'order_item', $this->get_id(), 'tax_amount', true ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 			$this->set_shipping_tax_total( get_metadata( 'order_item', $this->get_id(), 'shipping_tax_amount', true ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	 * Save properties specific to this order item. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	 * @return int Item ID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 	public function save() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 		parent::save(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 		if ( $this->get_id() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 			wc_update_order_item_meta( $this->get_id(), 'rate_id', $this->get_rate_id() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 			wc_update_order_item_meta( $this->get_id(), 'label', $this->get_label() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 			wc_update_order_item_meta( $this->get_id(), 'compound', $this->get_compound() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 			wc_update_order_item_meta( $this->get_id(), 'tax_amount', $this->get_tax_total() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 			wc_update_order_item_meta( $this->get_id(), 'shipping_tax_amount', $this->get_shipping_tax_total() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		return $this->get_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	 * Internal meta keys we don't want exposed as part of meta_data. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	 * @return array() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 	protected function get_internal_meta_keys() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 		return array( 'rate_id', 'label', 'compound', 'tax_amount', 'shipping_tax_amount' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 	 * Is this a compound tax rate? | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 	 * @return boolean | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 	public function is_compound() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 		return $this->get_compound(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 	/* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 	|-------------------------------------------------------------------------- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 	| Setters | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 	|-------------------------------------------------------------------------- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	 * Set order item name. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 	 * @param string $value | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 88 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  | 	public function set_name( $value ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  | 		$this->set_rate_code( $value ); | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 	 * Set item name. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 	 * @param string $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 	public function set_rate_code( $value ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 		$this->_data['rate_code'] = wc_clean( $value ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 	 * Set item name. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 	 * @param string $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 	public function set_label( $value ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 		$this->_data['label'] = wc_clean( $value ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 	 * Set tax rate id. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 	 * @param int $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 	public function set_rate_id( $value ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 		$this->_data['rate_id'] = absint( $value ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 	 * Set tax total. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 	 * @param string $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 	public function set_tax_total( $value ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 		$this->_data['tax_total'] = wc_format_decimal( $value ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 	 * Set shipping_tax_total | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 	 * @param string $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 	public function set_shipping_tax_total( $value ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 		$this->_data['shipping_tax_total'] = wc_format_decimal( $value ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 	 * Set compound | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 	 * @param bool $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 	public function set_compound( $value ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 		$this->_data['compound'] = (bool) $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 	/* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 	|-------------------------------------------------------------------------- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 	| Getters | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 	|-------------------------------------------------------------------------- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 	 * Get order item type. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 	public function get_type() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 		return 'tax'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  | 	 * Get rate code/name. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 	public function get_name() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  | 		return $this->get_rate_code(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  | 	 * Get rate code/name. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  | 	public function get_rate_code() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  | 		return $this->_data['rate_code']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  | 	 * Get label. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  | 	public function get_label() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  | 		return $this->_data['label'] ? $this->_data['label'] : __( 'Tax', 'woocommerce' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  | 	 * Get tax rate ID. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  | 	 * @return int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  | 	public function get_rate_id() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  | 		return absint( $this->_data['rate_id'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  | 	 * Get tax_total | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  | 	public function get_tax_total() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  | 		return wc_format_decimal( $this->_data['tax_total'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  | 	 * Get shipping_tax_total | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  | 	public function get_shipping_tax_total() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  | 		return wc_format_decimal( $this->_data['shipping_tax_total'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  | 	 * Get compound. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  | 	 * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  | 	public function get_compound() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  | 		return (bool) $this->_data['compound']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 210 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 211 |  |  |  | 
            
                        
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.