WC_Correios_Shipping_Carta_Registrada

Carta Registrada shipping method class.

Defined (1)

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

/includes/shipping/class-wc-correios-shipping-carta-registrada.php  
  1. class WC_Correios_Shipping_Carta_Registrada extends WC_Correios_Shipping_Carta { 
  2.  
  3. /** 
  4. * Initialize Carta Registrada. 
  5. * @param int $instance_id Shipping zone instance. 
  6. */ 
  7. public function __construct( $instance_id = 0 ) { 
  8. $this->id = 'correios-carta-registrada'; 
  9. $this->method_title = __( 'Carta Registrada', 'woocommerce-correios' ); 
  10. $this->more_link = 'http://www.correios.com.br/para-voce/correios-de-a-a-z/carta-comercial'; 
  11.  
  12. parent::__construct( $instance_id ); 
  13.  
  14. /** 
  15. * Get costs. 
  16. * Costs based in 28/06/2016 from: 
  17. * http://www.correios.com.br/para-voce/consultas-e-solicitacoes/precos-e-prazos/servicos-nacionais_pasta/carta 
  18. * @return array 
  19. */ 
  20. protected function get_costs() { 
  21. return apply_filters( 'woocommerce_correios_carta_registrada_costs', array( 
  22. '20' => array( 
  23. 'R' => 6.00,  
  24. 'AR' => 10.30,  
  25. 'MP' => 11.50,  
  26. 'AR+MP' => 15.80,  
  27. ),  
  28. '50' => array( 
  29. 'R' => 6.65,  
  30. 'AR' => 10.95,  
  31. 'MP' => 12.15,  
  32. 'AR+MP' => 16.45,  
  33. ),  
  34. '100' => array( 
  35. 'R' => 7.55,  
  36. 'AR' => 11.85,  
  37. 'MP' => 13.05,  
  38. 'AR+MP' => 17.35,  
  39. ),  
  40. '150' => array( 
  41. 'R' => 8.30,  
  42. 'AR' => 12.60,  
  43. 'MP' => 13.80,  
  44. 'AR+MP' => 18.10,  
  45. ),  
  46. '200' => array( 
  47. 'R' => 9.00,  
  48. 'AR' => 13.30,  
  49. 'MP' => 14.50,  
  50. 'AR+MP' => 18.80,  
  51. ),  
  52. '250' => array( 
  53. 'R' => 9.70,  
  54. 'AR' => 14.00,  
  55. 'MP' => 15.20,  
  56. 'AR+MP' => 19.50,  
  57. ),  
  58. '300' => array( 
  59. 'R' => 10.50,  
  60. 'AR' => 14.80,  
  61. 'MP' => 16.00,  
  62. 'AR+MP' => 20.30,  
  63. ),  
  64. '350' => array( 
  65. 'R' => 11.25,  
  66. 'AR' => 15.55,  
  67. 'MP' => 16.75,  
  68. 'AR+MP' => 21.05,  
  69. ),  
  70. '400' => array( 
  71. 'R' => 11.95,  
  72. 'AR' => 16.25,  
  73. 'MP' => 17.45,  
  74. 'AR+MP' => 21.75,  
  75. ),  
  76. '450' => array( 
  77. 'R' => 12.65,  
  78. 'AR' => 16.95,  
  79. 'MP' => 18.15,  
  80. 'AR+MP' => 22.45,  
  81. ),  
  82. '500' => array( 
  83. 'R' => 13.40,  
  84. 'AR' => 17.70,  
  85. 'MP' => 18.90,  
  86. 'AR+MP' => 23.20,  
  87. ),  
  88. ), $this->id, $this->instance_id ); 
  89.  
  90. /** 
  91. * Get type of cost. 
  92. * @return string 
  93. */ 
  94. protected function get_type_of_cost() { 
  95. if ( 'yes' === $this->receipt_notice && 'yes' === $this->own_hands ) { 
  96. return 'AR+MP'; 
  97. } elseif ( 'yes' === $this->receipt_notice ) { 
  98. return 'AR'; 
  99. } elseif ( 'yes' === $this->own_hands ) { 
  100. return 'MP'; 
  101. } else { 
  102. return 'R'; 
  103.  
  104. /** 
  105. * Get shipping cost. 
  106. * @param array $package Order package. 
  107. * @return float 
  108. */ 
  109. protected function get_shipping_cost( $package ) { 
  110. $type = $this->get_type_of_cost(); 
  111. $cost = 0; 
  112.  
  113. if ( 'yes' === $this->debug ) { 
  114. $this->log->add( $this->id, 'Calculating cost for Carta Registrada' ); 
  115.  
  116. if ( '' === $this->shipping_class ) { 
  117. if ( 'yes' === $this->debug ) { 
  118. $this->log->add( $this->id, 'Error: No shipping class has been configured!' ); 
  119.  
  120. return 0; 
  121.  
  122. // Get the package weight and validate. 
  123. $weight = $this->get_package_weight( $package ); 
  124. if ( false === $weight ) { 
  125. return 0; 
  126.  
  127. foreach ( $this->get_costs() as $cost_weight => $costs ) { 
  128. if ( $weight <= $cost_weight ) { 
  129. $cost = $costs[ $type ]; 
  130. break; 
  131.  
  132. if ( 'yes' === $this->debug ) { 
  133. $this->log->add( $this->id, sprintf( 'Total cost for %sg%s: %s', $weight, 'R' !== $type ? ' and ' . $type : '', $cost ) ); 
  134.  
  135. return $cost;