WC_Shipping_Rate

WooCommerce Shipping Rate Class.

Defined (1)

The class is defined in the following location(s).

/includes/class-wc-shipping-rate.php  
  1. class WC_Shipping_Rate { 
  2.  
  3. /** @var string Rate ID. */ 
  4. public $id = ''; 
  5.  
  6. /** @var string Label for the rate. */ 
  7. public $label = ''; 
  8.  
  9. /** @var float Cost for the rate. */ 
  10. public $cost = 0; 
  11.  
  12. /** @var array Array of taxes for the rate. */ 
  13. public $taxes = array(); 
  14.  
  15. /** @var string Label for the rate. */ 
  16. public $method_id = ''; 
  17.  
  18. /** 
  19. * Stores meta data for this rate 
  20. * @since 2.6.0 
  21. * @var array 
  22. */ 
  23. private $meta_data = array(); 
  24.  
  25. /** 
  26. * Constructor. 
  27. * @param string $id 
  28. * @param string $label 
  29. * @param integer $cost 
  30. * @param array $taxes 
  31. * @param string $method_id 
  32. */ 
  33. public function __construct( $id = '', $label = '', $cost = 0, $taxes = array(), $method_id = '' ) { 
  34. $this->id = $id; 
  35. $this->label = $label; 
  36. $this->cost = $cost; 
  37. $this->taxes = ! empty( $taxes ) && is_array( $taxes ) ? $taxes : array(); 
  38. $this->method_id = $method_id; 
  39.  
  40. /** 
  41. * Get shipping tax. 
  42. * @return array 
  43. */ 
  44. public function get_shipping_tax() { 
  45. return apply_filters( 'woocommerce_get_shipping_tax', sizeof( $this->taxes ) > 0 && ! WC()->customer->get_is_vat_exempt() ? array_sum( $this->taxes ) : 0, $this ); 
  46.  
  47. /** 
  48. * Get label. 
  49. * @return string 
  50. */ 
  51. public function get_label() { 
  52. return apply_filters( 'woocommerce_shipping_rate_label', $this->label, $this ); 
  53.  
  54. /** 
  55. * Add some meta data for this rate. 
  56. * @since 2.6.0 
  57. * @param string $key 
  58. * @param string $value 
  59. */ 
  60. public function add_meta_data( $key, $value ) { 
  61. $this->meta_data[ wc_clean( $key ) ] = wc_clean( $value ); 
  62.  
  63. /** 
  64. * Get all meta data for this rate. 
  65. * @since 2.6.0 
  66. */ 
  67. public function get_meta_data() { 
  68. return $this->meta_data;