woocommerce/includes/class-wc-shipping-rate.php

95 lines
1.9 KiB
PHP
Raw Normal View History

<?php
2014-11-17 16:30:15 +00:00
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
2015-11-03 13:31:20 +00:00
* WooCommerce Shipping Rate Class.
*
* Simple Class for storing rates.
*
* @class WC_Shipping_Rate
2016-01-08 11:42:32 +00:00
* @version 2.6.0
* @package WooCommerce/Classes/Shipping
2013-02-20 17:14:46 +00:00
* @category Class
* @author WooThemes
*/
2014-11-17 16:30:15 +00:00
class WC_Shipping_Rate {
2014-11-17 16:30:15 +00:00
/** @var string Rate ID. */
public $id = '';
2014-11-17 16:30:15 +00:00
/** @var string Label for the rate. */
public $label = '';
/** @var float Cost for the rate. */
public $cost = 0;
/** @var array Array of taxes for the rate. */
public $taxes = array();
2014-11-17 16:30:15 +00:00
/** @var string Label for the rate. */
public $method_id = '';
2016-01-08 11:42:32 +00:00
/**
* Stores meta data for this rate
* @since 2.6.0
* @var array
*/
private $meta_data = array();
/**
2015-11-03 13:31:20 +00:00
* Constructor.
*
2014-11-17 16:30:15 +00:00
* @param string $id
* @param string $label
* @param integer $cost
2014-11-17 16:30:15 +00:00
* @param array $taxes
* @param string $method_id
*/
public function __construct( $id = '', $label = '', $cost = 0, $taxes = array(), $method_id = '' ) {
2016-01-08 11:42:32 +00:00
$this->id = $id;
$this->label = $label;
$this->cost = $cost;
$this->taxes = ! empty( $taxes ) && is_array( $taxes ) ? $taxes : array();
$this->method_id = $method_id;
}
/**
* Get shipping tax.
*
* @return array
*/
2014-11-17 16:30:15 +00:00
public function get_shipping_tax() {
2016-01-08 11:42:32 +00:00
return apply_filters( 'woocommerce_get_shipping_tax', sizeof( $this->taxes ) > 0 && ! WC()->customer->is_vat_exempt() ? array_sum( $this->taxes ) : 0, $this );
}
/**
2015-11-03 13:31:20 +00:00
* Get label.
*
* @return string
*/
public function get_label() {
return apply_filters( 'woocommerce_shipping_rate_label', $this->label );
}
2016-01-08 11:42:32 +00:00
/**
* Add some meta data for this rate.
* @since 2.6.0
* @param string $key
* @param string $value
*/
public function add_meta_data( $key, $value ) {
$this->meta_data[ wc_clean( $key ) ] = wc_clean( $value );
}
/**
* Get all meta data for this rate.
* @since 2.6.0
*/
public function get_meta_data() {
return $this->meta_data;
}
}