WC_Correios_Shipping_Impresso_Urgente

Impresso Urgente shipping method class.

Defined (1)

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

/includes/shipping/class-wc-correios-shipping-impresso-urgente.php  
  1. class WC_Correios_Shipping_Impresso_Urgente extends WC_Correios_Shipping_Impresso { 
  2.  
  3. /** 
  4. * Weight limit for this shipping method. 
  5. * Value based in 01/02/2017 from: 
  6. * https://www.correios.com.br/para-voce/consultas-e-solicitacoes/precos-e-prazos/servicos-nacionais_pasta/impresso-normal 
  7. * @var float 
  8. */ 
  9. protected $shipping_method_weight_limit = 500.000; 
  10.  
  11. /** 
  12. * Initialize Impresso Urgente. 
  13. * @param int $instance_id Shipping zone instance. 
  14. */ 
  15. public function __construct( $instance_id = 0 ) { 
  16. $this->id = 'correios-impresso-urgente'; 
  17. $this->method_title = __( 'Impresso Urgente', 'woocommerce-correios' ); 
  18. $this->more_link = 'http://www.correios.com.br/para-voce/correios-de-a-a-z/impresso-normal'; 
  19.  
  20. parent::__construct( $instance_id ); 
  21.  
  22. /** 
  23. * Get costs. 
  24. * Costs based in 01/02/2017 from: 
  25. * https://www.correios.com.br/para-voce/consultas-e-solicitacoes/precos-e-prazos/servicos-nacionais_pasta/impresso-normal 
  26. * @return array 
  27. */ 
  28. protected function get_costs() { 
  29. return apply_filters( 'woocommerce_correios_impresso_urgente_costs', array( 
  30. '20' => 1.50,  
  31. '50' => 2.10,  
  32. '100' => 2.85,  
  33. '150' => 3.50,  
  34. '200' => 4.10,  
  35. '250' => 4.80,  
  36. '300' => 5.40,  
  37. '350' => 6.05,  
  38. '400' => 6.60,  
  39. '450' => 7.30,  
  40. '500' => 7.90,  
  41. ), $this->id, $this->instance_id ); 
  42.  
  43. /** 
  44. * Get shipping cost. 
  45. * @param array $package Order package. 
  46. * @return float 
  47. */ 
  48. protected function get_shipping_cost( $package ) { 
  49. $cost = 0; 
  50.  
  51. if ( 'yes' === $this->debug ) { 
  52. $this->log->add( $this->id, 'Calculating cost for Impresso Urgente' ); 
  53.  
  54. if ( '' === $this->shipping_class ) { 
  55. if ( 'yes' === $this->debug ) { 
  56. $this->log->add( $this->id, 'Error: No shipping class has been configured!' ); 
  57.  
  58. return 0; 
  59.  
  60. // Get the package weight and validate. 
  61. $weight = $this->get_package_weight( $package ); 
  62. if ( false === $weight ) { 
  63. return 0; 
  64.  
  65. if ( $weight <= $this->shipping_method_weight_limit ) { 
  66. foreach ( $this->get_costs() as $cost_weights => $costs ) { 
  67. if ( $weight <= $cost_weights ) { 
  68. $cost = $costs; 
  69.  
  70. if ( 'yes' === $this->own_hands || 'RN' === $this->registry_type ) { 
  71. $cost += $this->national_registry_cost; 
  72. } else { 
  73. $cost += $this->reasonable_registry_cost; 
  74.  
  75. if ( 'yes' === $this->receipt_notice ) { 
  76. $cost += $this->receipt_notice_cost; 
  77.  
  78. if ( 'yes' === $this->own_hands ) { 
  79. $cost += $this->own_hands_cost; 
  80.  
  81. break; 
  82.  
  83. if ( 'yes' === $this->debug ) { 
  84. $this->log->add( $this->id, sprintf( 'Total cost for %sg and %s: %s', $weight, $this->registry_type, $cost ) ); 
  85. } else { 
  86. if ( 'yes' === $this->debug ) { 
  87. $this->log->add( $this->id, sprintf( 'The cart weight of %.3f exceeds the shipping method supported weight limit of %.3f', $weight, $this->shipping_method_weight_limit ) ); 
  88.  
  89. return $cost;