2016-06-21 19:10:09 +00:00
|
|
|
<?php
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Order Line Item (tax).
|
|
|
|
*
|
|
|
|
* @version 2.7.0
|
|
|
|
* @since 2.7.0
|
|
|
|
* @package WooCommerce/Classes
|
|
|
|
* @author WooThemes
|
|
|
|
*/
|
|
|
|
class WC_Order_Item_Tax extends WC_Order_Item {
|
|
|
|
|
|
|
|
/**
|
2016-08-25 12:31:03 +00:00
|
|
|
* Order Data array. This is the core order data exposed in APIs since 2.7.0.
|
2016-06-21 19:10:09 +00:00
|
|
|
* @since 2.7.0
|
|
|
|
* @var array
|
|
|
|
*/
|
2016-11-17 21:30:34 +00:00
|
|
|
protected $extra_data = array(
|
2016-06-21 19:10:09 +00:00
|
|
|
'rate_code' => '',
|
|
|
|
'rate_id' => 0,
|
|
|
|
'label' => '',
|
|
|
|
'compound' => false,
|
|
|
|
'tax_total' => 0,
|
2016-08-27 01:46:45 +00:00
|
|
|
'shipping_tax_total' => 0,
|
2016-06-21 19:10:09 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| Setters
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set order item name.
|
2016-11-17 21:30:34 +00:00
|
|
|
*
|
2016-06-21 19:10:09 +00:00
|
|
|
* @param string $value
|
2016-08-24 09:46:29 +00:00
|
|
|
* @throws WC_Data_Exception
|
2016-06-21 19:10:09 +00:00
|
|
|
*/
|
|
|
|
public function set_name( $value ) {
|
2016-08-26 09:54:18 +00:00
|
|
|
$this->set_rate_code( $value );
|
2016-06-21 19:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set item name.
|
2016-11-17 21:30:34 +00:00
|
|
|
*
|
2016-06-21 19:10:09 +00:00
|
|
|
* @param string $value
|
2016-08-24 09:46:29 +00:00
|
|
|
* @throws WC_Data_Exception
|
2016-06-21 19:10:09 +00:00
|
|
|
*/
|
|
|
|
public function set_rate_code( $value ) {
|
2016-11-17 21:30:34 +00:00
|
|
|
$this->set_prop( 'rate_code', wc_clean( $value ) );
|
2016-06-21 19:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set item name.
|
|
|
|
* @param string $value
|
2016-08-24 09:46:29 +00:00
|
|
|
* @throws WC_Data_Exception
|
2016-06-21 19:10:09 +00:00
|
|
|
*/
|
|
|
|
public function set_label( $value ) {
|
2016-11-17 21:30:34 +00:00
|
|
|
$this->set_prop( 'label', wc_clean( $value ) );
|
2016-06-21 19:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set tax rate id.
|
|
|
|
* @param int $value
|
2016-08-24 09:46:29 +00:00
|
|
|
* @throws WC_Data_Exception
|
2016-06-21 19:10:09 +00:00
|
|
|
*/
|
|
|
|
public function set_rate_id( $value ) {
|
2016-11-17 21:30:34 +00:00
|
|
|
$this->set_prop( 'rate_id', absint( $value ) );
|
2016-06-21 19:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set tax total.
|
|
|
|
* @param string $value
|
2016-08-24 09:46:29 +00:00
|
|
|
* @throws WC_Data_Exception
|
2016-06-21 19:10:09 +00:00
|
|
|
*/
|
|
|
|
public function set_tax_total( $value ) {
|
2016-11-17 21:30:34 +00:00
|
|
|
$this->set_prop( 'tax_total', wc_format_decimal( $value ) );
|
2016-06-21 19:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set shipping_tax_total
|
|
|
|
* @param string $value
|
2016-08-24 09:46:29 +00:00
|
|
|
* @throws WC_Data_Exception
|
2016-06-21 19:10:09 +00:00
|
|
|
*/
|
|
|
|
public function set_shipping_tax_total( $value ) {
|
2016-11-17 21:30:34 +00:00
|
|
|
$this->set_prop( 'shipping_tax_total', wc_format_decimal( $value ) );
|
2016-06-21 19:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set compound
|
|
|
|
* @param bool $value
|
2016-08-24 09:46:29 +00:00
|
|
|
* @throws WC_Data_Exception
|
2016-06-21 19:10:09 +00:00
|
|
|
*/
|
|
|
|
public function set_compound( $value ) {
|
2016-11-17 21:30:34 +00:00
|
|
|
$this->set_prop( 'compound', (bool) $value );
|
2016-06-21 19:10:09 +00:00
|
|
|
}
|
|
|
|
|
2016-08-22 13:52:03 +00:00
|
|
|
/**
|
|
|
|
* Set properties based on passed in tax rate by ID.
|
|
|
|
* @param int $tax_rate_id
|
2016-08-24 09:46:29 +00:00
|
|
|
* @throws WC_Data_Exception
|
2016-08-22 13:52:03 +00:00
|
|
|
*/
|
|
|
|
public function set_rate( $tax_rate_id ) {
|
|
|
|
$this->set_rate_id( $tax_rate_id );
|
|
|
|
$this->set_rate_code( WC_Tax::get_rate_code( $tax_rate_id ) );
|
|
|
|
$this->set_label( WC_Tax::get_rate_code( $tax_rate_id ) );
|
|
|
|
$this->set_compound( WC_Tax::get_rate_code( $tax_rate_id ) );
|
|
|
|
}
|
|
|
|
|
2016-06-21 19:10:09 +00:00
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| Getters
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get order item type.
|
2016-11-17 21:30:34 +00:00
|
|
|
*
|
2016-06-21 19:10:09 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2016-11-18 11:33:31 +00:00
|
|
|
public function get_type() {
|
2016-06-21 19:10:09 +00:00
|
|
|
return 'tax';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get rate code/name.
|
2016-11-17 21:30:34 +00:00
|
|
|
*
|
|
|
|
* @param string $context
|
2016-06-21 19:10:09 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2016-11-17 21:30:34 +00:00
|
|
|
public function get_name( $context = 'view' ) {
|
|
|
|
return $this->get_rate_code( $context );
|
2016-06-21 19:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get rate code/name.
|
2016-11-17 21:30:34 +00:00
|
|
|
*
|
|
|
|
* @param string $context
|
2016-06-21 19:10:09 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2016-11-17 21:30:34 +00:00
|
|
|
public function get_rate_code( $context = 'view' ) {
|
|
|
|
return $this->get_prop( 'rate_code', $context );
|
2016-06-21 19:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get label.
|
2016-11-17 21:30:34 +00:00
|
|
|
*
|
|
|
|
* @param string $context
|
2016-06-21 19:10:09 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2016-11-17 21:30:34 +00:00
|
|
|
public function get_label( $context = 'view' ) {
|
|
|
|
$label = $this->get_prop( 'label', $context );
|
2016-11-21 12:14:53 +00:00
|
|
|
if ( 'view' === $context ) {
|
|
|
|
return $label ? $label : __( 'Tax', 'woocommerce' );
|
|
|
|
} else {
|
|
|
|
return $label;
|
|
|
|
}
|
2016-06-21 19:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get tax rate ID.
|
2016-11-17 21:30:34 +00:00
|
|
|
*
|
|
|
|
* @param string $context
|
2016-06-21 19:10:09 +00:00
|
|
|
* @return int
|
|
|
|
*/
|
2016-11-17 21:30:34 +00:00
|
|
|
public function get_rate_id( $context = 'view' ) {
|
|
|
|
return $this->get_prop( 'rate_id', $context );
|
2016-06-21 19:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get tax_total
|
2016-11-17 21:30:34 +00:00
|
|
|
*
|
|
|
|
* @param string $context
|
2016-06-21 19:10:09 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2016-11-17 21:30:34 +00:00
|
|
|
public function get_tax_total( $context = 'view' ) {
|
|
|
|
return $this->get_prop( 'tax_total', $context );
|
2016-06-21 19:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get shipping_tax_total
|
2016-11-17 21:30:34 +00:00
|
|
|
*
|
|
|
|
* @param string $context
|
2016-06-21 19:10:09 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2016-11-17 21:30:34 +00:00
|
|
|
public function get_shipping_tax_total( $context = 'view' ) {
|
|
|
|
return $this->get_prop( 'shipping_tax_total', $context );
|
2016-06-21 19:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get compound.
|
2016-11-17 21:30:34 +00:00
|
|
|
*
|
|
|
|
* @param string $context
|
2016-06-21 19:10:09 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2016-11-17 21:30:34 +00:00
|
|
|
public function get_compound( $context = 'view' ) {
|
|
|
|
return $this->get_prop( 'compound', $context );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| Other
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal meta keys we don't want exposed as part of meta_data.
|
|
|
|
* @return array()
|
|
|
|
*/
|
|
|
|
protected function get_internal_meta_keys() {
|
|
|
|
return array( 'rate_id', 'label', 'compound', 'tax_amount', 'shipping_tax_amount' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is this a compound tax rate?
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function is_compound() {
|
|
|
|
return $this->get_compound();
|
2016-06-21 19:10:09 +00:00
|
|
|
}
|
|
|
|
}
|