WooCommerce Correios - Version 3.0.0

Version Description

  • 2016/06/26 =

  • Reformulao geral de todos o cdigo do plugin.

  • Adicionado suporte as reas de entrega do WooCommerce 2.6.

  • Adicionado os mtodos de SEDEX 10 Envelope, SEDEX 12, Carta Registrada, Mercadoria Expressa, Mercadoria Econmica e Leve Internacional.

  • Adicionado novo menu de "integraes".

  • Adicionada integrao com o servio de consulta de CEP e assim adicionando uma opo para autopreencher endereos com base no CEP.

  • Atualizada a integrao com o sistema que gera o histrico de rastreamento do pedido.

  • Removida a opo de simulador de frete do carrinho.

  • Integrado o campo de "correios_tracking_code" dos pedidos com a API REST do WooCommerce.

  • E mais outras vrias alteraes que podem ser verificadas pelo GitHub.

=

Download this release

Release Info

Developer claudiosanches
Plugin Icon 128x128 WooCommerce Correios
Version 3.0.0
Comparing to
See all releases

Version 3.0.0

Files changed (44) hide show
  1. assets/js/admin/integration.js +52 -0
  2. assets/js/admin/integration.min.js +1 -0
  3. assets/js/admin/shipping-methods.js +24 -0
  4. assets/js/admin/shipping-methods.min.js +1 -0
  5. assets/js/frontend/autofill-address.js +133 -0
  6. assets/js/frontend/autofill-address.min.js +8 -0
  7. includes/abstracts/abstract-wc-correios-international-shipping.php +226 -0
  8. includes/abstracts/abstract-wc-correios-shipping.php +459 -0
  9. includes/admin/class-wc-correios-admin-orders.php +67 -0
  10. includes/admin/views/html-admin-help-message.php +17 -0
  11. includes/admin/views/html-admin-missing-dependencies.php +36 -0
  12. includes/admin/views/html-admin-shipping-method-settings.php +26 -0
  13. includes/class-wc-correios-autofill-addresses.php +314 -0
  14. includes/class-wc-correios-install.php +75 -0
  15. includes/class-wc-correios-package.php +248 -0
  16. includes/class-wc-correios-rest-api.php +112 -0
  17. includes/class-wc-correios-soap-client.php +42 -0
  18. includes/class-wc-correios-tracking-history.php +146 -0
  19. includes/class-wc-correios-webservice-international.php +652 -0
  20. includes/class-wc-correios-webservice.php +558 -0
  21. includes/emails/class-wc-correios-tracking-email.php +204 -0
  22. includes/integrations/class-wc-correios-integration.php +290 -0
  23. includes/shipping/class-wc-correios-shipping-carta-registrada.php +39 -0
  24. includes/shipping/class-wc-correios-shipping-esedex.php +39 -0
  25. includes/shipping/class-wc-correios-shipping-legacy.php +453 -0
  26. includes/shipping/class-wc-correios-shipping-leve-internacional.php +39 -0
  27. includes/shipping/class-wc-correios-shipping-mercadoria-economica.php +39 -0
  28. includes/shipping/class-wc-correios-shipping-mercadoria-expressa.php +39 -0
  29. includes/shipping/class-wc-correios-shipping-pac.php +47 -0
  30. includes/shipping/class-wc-correios-shipping-sedex-hoje.php +39 -0
  31. includes/shipping/class-wc-correios-shipping-sedex.php +47 -0
  32. includes/shipping/class-wc-correios-shipping-sedex10-envelope.php +39 -0
  33. includes/shipping/class-wc-correios-shipping-sedex10-pacote.php +39 -0
  34. includes/shipping/class-wc-correios-shipping-sedex12.php +39 -0
  35. includes/wc-correios-functions.php +160 -0
  36. languages/woocommerce-correios.pot +830 -0
  37. readme.txt +226 -0
  38. templates/emails/correios-tracking-code.php +84 -0
  39. templates/emails/plain/correios-tracking-code.php +68 -0
  40. templates/myaccount/tracking-code.php +17 -0
  41. templates/myaccount/tracking-history-table.php +42 -0
  42. uninstall.php +16 -0
  43. wc-correios.php +21 -0
  44. woocommerce-correios.php +224 -0
assets/js/admin/integration.js ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* global ajaxurl, WCCorreiosIntegrationAdminParams */
2
+ jQuery( function( $ ) {
3
+
4
+ /**
5
+ * Admin class.
6
+ *
7
+ * @type {Object}
8
+ */
9
+ var WCCorreiosIntegrationAdmin = {
10
+
11
+ /**
12
+ * Initialize actions.
13
+ */
14
+ init: function() {
15
+ $( document.body ).on( 'click', '#woocommerce_correios-integration_autofill_empty_database', this.empty_database );
16
+ },
17
+
18
+ /**
19
+ * Empty database.
20
+ *
21
+ * @return {String}
22
+ */
23
+ empty_database: function() {
24
+ if ( ! window.confirm( WCCorreiosIntegrationAdminParams.i18n_confirm_message ) ) {
25
+ return;
26
+ }
27
+
28
+ $( '#mainform' ).block({
29
+ message: null,
30
+ overlayCSS: {
31
+ background: '#fff',
32
+ opacity: 0.6
33
+ }
34
+ });
35
+
36
+ $.ajax({
37
+ type: 'POST',
38
+ url: ajaxurl,
39
+ data: {
40
+ action: 'correios_autofill_addresses_empty_database',
41
+ nonce: WCCorreiosIntegrationAdminParams.empty_database_nonce
42
+ },
43
+ success: function( response ) {
44
+ window.alert( response.data.message );
45
+ $( '#mainform' ).unblock();
46
+ }
47
+ });
48
+ }
49
+ };
50
+
51
+ WCCorreiosIntegrationAdmin.init();
52
+ });
assets/js/admin/integration.min.js ADDED
@@ -0,0 +1 @@
 
1
+ jQuery(function(a){var b={init:function(){a(document.body).on("click","#woocommerce_correios-integration_autofill_empty_database",this.empty_database)},empty_database:function(){window.confirm(WCCorreiosIntegrationAdminParams.i18n_confirm_message)&&(a("#mainform").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),a.ajax({type:"POST",url:ajaxurl,data:{action:"correios_autofill_addresses_empty_database",nonce:WCCorreiosIntegrationAdminParams.empty_database_nonce},success:function(b){window.alert(b.data.message),a("#mainform").unblock()}}))}};b.init()});
assets/js/admin/shipping-methods.js ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery( document ).ready( function( $ ) {
2
+ $( 'input[id$="_show_delivery_time"], #woocommerce_correios_display_date' ).on( 'change', function() {
3
+ var field = $( 'input[id$="_additional_time"]' ).closest( 'tr' );
4
+
5
+ if ( $( this ).is( ':checked' ) ) {
6
+ field.show();
7
+ } else {
8
+ field.hide();
9
+ }
10
+ }).change();
11
+
12
+ $( 'select[id$="_service_type"], #woocommerce_correios_corporate_service' ).on( 'change', function() {
13
+ var login = $( 'input[id$="_login"]' ).closest( 'tr' ),
14
+ password = $( 'input[id$="_password"]' ).closest( 'tr' );
15
+
16
+ if ( 'corporate' === $( this ).val() ) {
17
+ login.show();
18
+ password.show();
19
+ } else {
20
+ login.hide();
21
+ password.hide();
22
+ }
23
+ }).change();
24
+ });
assets/js/admin/shipping-methods.min.js ADDED
@@ -0,0 +1 @@
 
1
+ jQuery(document).ready(function(a){a('input[id$="_show_delivery_time"], #woocommerce_correios_display_date').on("change",function(){var b=a('input[id$="_additional_time"]').closest("tr");a(this).is(":checked")?b.show():b.hide()}).change(),a('select[id$="_service_type"], #woocommerce_correios_corporate_service').on("change",function(){var b=a('input[id$="_login"]').closest("tr"),c=a('input[id$="_password"]').closest("tr");"corporate"===a(this).val()?(b.show(),c.show()):(b.hide(),c.hide())}).change()});
assets/js/frontend/autofill-address.js ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* global WCCorreiosAutofillAddressParams */
2
+ /*!
3
+ * WooCommerce Correios Autofill Brazilian 2016.
4
+ *
5
+ * Autofill address with postcodes.
6
+ *
7
+ * Version: 3.0.0
8
+ */
9
+
10
+ jQuery( function( $ ) {
11
+
12
+ /**
13
+ * Autofill address class.
14
+ *
15
+ * @type {Object}
16
+ */
17
+ var WCCorreiosAutofillAddress = {
18
+
19
+ /**
20
+ * Initialize actions.
21
+ */
22
+ init: function() {
23
+ // Initial load.
24
+ this.autofill( 'billing', true );
25
+
26
+ $( document.body ).on( 'blur', '#billing_postcode', function() {
27
+ WCCorreiosAutofillAddress.autofill( 'billing' );
28
+ });
29
+ $( document.body ).on( 'blur', '#shipping_postcode', function() {
30
+ WCCorreiosAutofillAddress.autofill( 'shipping' );
31
+ });
32
+ },
33
+
34
+ /**
35
+ * Block checkout.
36
+ */
37
+ block: function() {
38
+ $( 'form.checkout, form#order_review' )
39
+ .addClass( 'processing' )
40
+ .block({
41
+ message: null,
42
+ overlayCSS: {
43
+ background: '#fff',
44
+ opacity: 0.6
45
+ }
46
+ });
47
+ },
48
+
49
+ /**
50
+ * Unblock checkout.
51
+ */
52
+ unblock: function() {
53
+ $( 'form.checkout, form#order_review' )
54
+ .removeClass( 'processing' )
55
+ .unblock();
56
+ },
57
+
58
+ /**
59
+ * Autocomplate address.
60
+ *
61
+ * @param {String} field Target.
62
+ * @param {Boolean} copy
63
+ */
64
+ autofill: function( field, copy ) {
65
+ copy = copy || false;
66
+
67
+ // Checks with *_postcode field exist.
68
+ if ( $( '#' + field + '_postcode' ).length ) {
69
+
70
+ // Valid CEP.
71
+ var cep = $( '#' + field + '_postcode' ).val().replace( '.', '' ).replace( '-', '' ),
72
+ country = $( '#' + field + '_country' ).val(),
73
+ address_1 = $( '#' + field + '_address_1' ).val(),
74
+ override = ( 'yes' === WCCorreiosAutofillAddressParams.force ) ? true : ( 0 === address_1.length );
75
+
76
+ // Check country is BR.
77
+ if ( cep !== '' && 8 === cep.length && 'BR' === country && override ) {
78
+
79
+ WCCorreiosAutofillAddress.block();
80
+
81
+ // Gets the address.
82
+ $.ajax({
83
+ type: 'GET',
84
+ url: WCCorreiosAutofillAddressParams.url + '&postcode=' + cep,
85
+ dataType: 'json',
86
+ contentType: 'application/json',
87
+ success: function( address ) {
88
+ if ( address.success ) {
89
+ WCCorreiosAutofillAddress.fillFields( field, address.data );
90
+
91
+ if ( copy ) {
92
+ var newField = 'billing' === field ? 'shipping' : 'billing';
93
+
94
+ WCCorreiosAutofillAddress.fillFields( newField, address.data );
95
+ }
96
+ }
97
+
98
+ WCCorreiosAutofillAddress.unblock();
99
+ }
100
+ });
101
+ }
102
+ }
103
+ },
104
+
105
+ /**
106
+ * Fill fields.
107
+ *
108
+ * @param {String} field
109
+ * @param {Object} data
110
+ */
111
+ fillFields: function( field, data ) {
112
+ // Address.
113
+ $( '#' + field + '_address_1' ).val( data.address ).change();
114
+
115
+ // Neighborhood.
116
+ if ( $( '#' + field + '_neighborhood' ).length ) {
117
+ $( '#' + field + '_neighborhood' ).val( data.neighborhood ).change();
118
+ } else {
119
+ $( '#' + field + '_address_2' ).val( data.neighborhood ).change();
120
+ }
121
+
122
+ // City.
123
+ $( '#' + field + '_city' ).val( data.city ).change();
124
+
125
+ // State.
126
+ $( '#' + field + '_state option:selected' ).attr( 'selected', false ).change();
127
+ $( '#' + field + '_state option[value="' + data.state + '"]' ).attr( 'selected', 'selected' ).change();
128
+ $( '#' + field + '_state' ).trigger( 'liszt:updated' ).trigger( 'chosen:updated' ); // Chosen support.
129
+ }
130
+ };
131
+
132
+ WCCorreiosAutofillAddress.init();
133
+ });
assets/js/frontend/autofill-address.min.js ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * WooCommerce Correios Autofill Brazilian 2016.
3
+ *
4
+ * Autofill address with postcodes.
5
+ *
6
+ * Version: 3.0.0
7
+ */
8
+ jQuery(function(a){var b={init:function(){this.autofill("billing",!0),a(document.body).on("blur","#billing_postcode",function(){b.autofill("billing")}),a(document.body).on("blur","#shipping_postcode",function(){b.autofill("shipping")})},block:function(){a("form.checkout, form#order_review").addClass("processing").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){a("form.checkout, form#order_review").removeClass("processing").unblock()},autofill:function(c,d){if(d=d||!1,a("#"+c+"_postcode").length){var e=a("#"+c+"_postcode").val().replace(".","").replace("-",""),f=a("#"+c+"_country").val(),g=a("#"+c+"_address_1").val(),h="yes"===WCCorreiosAutofillAddressParams.force?!0:0===g.length;""!==e&&8===e.length&&"BR"===f&&h&&(b.block(),a.ajax({type:"GET",url:WCCorreiosAutofillAddressParams.url+"&postcode="+e,dataType:"json",contentType:"application/json",success:function(a){if(a.success&&(b.fillFields(c,a.data),d)){var e="billing"===c?"shipping":"billing";b.fillFields(e,a.data)}b.unblock()}}))}},fillFields:function(b,c){a("#"+b+"_address_1").val(c.address).change(),a("#"+b+"_neighborhood").length?a("#"+b+"_neighborhood").val(c.neighborhood).change():a("#"+b+"_address_2").val(c.neighborhood).change(),a("#"+b+"_city").val(c.city).change(),a("#"+b+"_state option:selected").attr("selected",!1).change(),a("#"+b+'_state option[value="'+c.state+'"]').attr("selected","selected").change(),a("#"+b+"_state").trigger("liszt:updated").trigger("chosen:updated")}};b.init()});
includes/abstracts/abstract-wc-correios-international-shipping.php ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Abstract Correios international shipping method.
4
+ *
5
+ * @package WooCommerce_Correios/Abstracts
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * Default Correios international shipping method abstract class.
16
+ *
17
+ * This is a abstract method with default options for all methods.
18
+ */
19
+ abstract class WC_Correios_International_Shipping extends WC_Correios_Shipping {
20
+
21
+ /**
22
+ * Initialize the Correios shipping method.
23
+ *
24
+ * @param int $instance_id Shipping zone instance ID.
25
+ */
26
+ public function __construct( $instance_id = 0 ) {
27
+ $this->instance_id = absint( $instance_id );
28
+ $this->method_description = sprintf( __( '%s is a international shipping method from Correios.', 'woocommerce-correios' ), $this->method_title );
29
+ $this->supports = array(
30
+ 'shipping-zones',
31
+ 'instance-settings',
32
+ );
33
+
34
+ // Load the form fields.
35
+ $this->init_form_fields();
36
+
37
+ // Define user set variables.
38
+ $this->enabled = $this->get_option( 'enabled' );
39
+ $this->title = $this->get_option( 'title' );
40
+ $this->origin_state = $this->get_option( 'origin_state' );
41
+ $this->origin_location = $this->get_option( 'origin_location' );
42
+ $this->show_delivery_time = $this->get_option( 'show_delivery_time' );
43
+ $this->fee = $this->get_option( 'fee' );
44
+ $this->automatic_insurance = $this->get_option( 'automatic_insurance' );
45
+ $this->debug = $this->get_option( 'debug' );
46
+
47
+ // Active logs.
48
+ if ( 'yes' == $this->debug ) {
49
+ $this->log = new WC_Logger();
50
+ }
51
+
52
+ // Save admin options.
53
+ add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
54
+ }
55
+
56
+ /**
57
+ * Admin options fields.
58
+ */
59
+ public function init_form_fields() {
60
+ $this->instance_form_fields = array();
61
+
62
+ $this->instance_form_fields['enabled'] = array(
63
+ 'title' => __( 'Enable/Disable', 'woocommerce-correios' ),
64
+ 'type' => 'checkbox',
65
+ 'label' => __( 'Enable this shipping method', 'woocommerce-correios' ),
66
+ 'default' => 'yes',
67
+ );
68
+ $this->instance_form_fields['title'] = array(
69
+ 'title' => __( 'Title', 'woocommerce-correios' ),
70
+ 'type' => 'text',
71
+ 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-correios' ),
72
+ 'desc_tip' => true,
73
+ 'default' => $this->method_title,
74
+ );
75
+ $this->instance_form_fields['behavior_options'] = array(
76
+ 'title' => __( 'Behavior Options', 'woocommerce-correios' ),
77
+ 'type' => 'title',
78
+ 'default' => '',
79
+ );
80
+ $this->instance_form_fields['origin_state'] = array(
81
+ 'title' => __( 'Origin State', 'woocommerce-correios' ),
82
+ 'type' => 'select',
83
+ 'description' => __( 'The UF of the location your packages are delivered from.', 'woocommerce-correios' ),
84
+ 'desc_tip' => true,
85
+ 'default' => '',
86
+ 'class' => 'wc-enhanced-select',
87
+ 'options' => WC()->countries->get_states( 'BR' ),
88
+ );
89
+ $this->instance_form_fields['origin_location'] = array(
90
+ 'title' => __( 'Origin Locale', 'woocommerce-correios' ),
91
+ 'type' => 'select',
92
+ 'description' => __( 'The location of your packages are delivered from.', 'woocommerce-correios' ),
93
+ 'desc_tip' => true,
94
+ 'default' => 'C',
95
+ 'class' => 'wc-enhanced-select',
96
+ 'options' => array(
97
+ 'C' => __( 'Capital', 'woocommerce-correios' ),
98
+ 'I' => __( 'Interior', 'woocommerce-correios' ),
99
+ ),
100
+ );
101
+ $this->instance_form_fields['show_delivery_time'] = array(
102
+ 'title' => __( 'Delivery Time', 'woocommerce-correios' ),
103
+ 'type' => 'checkbox',
104
+ 'label' => __( 'Show estimated delivery time', 'woocommerce-correios' ),
105
+ 'description' => __( 'Display the estimated delivery time in working days.', 'woocommerce-correios' ),
106
+ 'desc_tip' => true,
107
+ 'default' => 'no',
108
+ );
109
+ $this->instance_form_fields['fee'] = array(
110
+ 'title' => __( 'Handling Fee', 'woocommerce-correios' ),
111
+ 'type' => 'price',
112
+ 'description' => __( 'Enter an amount, e.g. 2.50, or a percentage, e.g. 5%. Leave blank to disable.', 'woocommerce-correios' ),
113
+ 'desc_tip' => true,
114
+ 'placeholder' => '0.00',
115
+ 'default' => '',
116
+ );
117
+ $this->instance_form_fields['optional_services'] = array(
118
+ 'title' => __( 'Optional Services', 'woocommerce-correios' ),
119
+ 'type' => 'title',
120
+ 'description' => __( 'Use these options to add the value of each service provided by the Correios.', 'woocommerce-correios' ),
121
+ 'default' => '',
122
+ );
123
+ $this->instance_form_fields['automatic_insurance'] = array(
124
+ 'title' => __( 'Automatic Insurance', 'woocommerce-correios' ),
125
+ 'type' => 'checkbox',
126
+ 'label' => __( 'Enable automatic insurance', 'woocommerce-correios' ),
127
+ 'description' => __( 'This controls if need to apply insurance to the order.', 'woocommerce-correios' ),
128
+ 'desc_tip' => true,
129
+ 'default' => 'yes',
130
+ );
131
+ $this->instance_form_fields['testing'] = array(
132
+ 'title' => __( 'Testing', 'woocommerce-correios' ),
133
+ 'type' => 'title',
134
+ 'default' => '',
135
+ );
136
+ $this->instance_form_fields['debug'] = array(
137
+ 'title' => __( 'Debug Log', 'woocommerce-correios' ),
138
+ 'type' => 'checkbox',
139
+ 'label' => __( 'Enable logging', 'woocommerce-correios' ),
140
+ 'default' => 'no',
141
+ 'description' => sprintf( __( 'Log %s events, such as WebServices requests.', 'woocommerce-correios' ), $this->method_title ) . $this->get_log_link(),
142
+ );
143
+ }
144
+
145
+ /**
146
+ * Get Correios service code.
147
+ *
148
+ * @return string
149
+ */
150
+ public function get_code() {
151
+ return apply_filters( 'woocommerce_correios_shipping_method_code', $this->code, $this->id, $this->instance_id );
152
+ }
153
+
154
+ /**
155
+ * Get shipping rate.
156
+ *
157
+ * @param array $package Order package.
158
+ *
159
+ * @return SimpleXMLElement
160
+ */
161
+ protected function get_rate( $package ) {
162
+ $api = new WC_Correios_Webservice_International( $this->id, $this->instance_id );
163
+ $api->set_debug( $this->debug );
164
+ $api->set_service( $this->get_code() );
165
+ $api->set_package( $package );
166
+ $api->set_destination_country( $package['destination']['country'] );
167
+ $api->set_origin_state( $this->origin_state );
168
+ $api->set_origin_location( $this->origin_location );
169
+
170
+ $shipping = $api->get_shipping();
171
+
172
+ return $shipping;
173
+ }
174
+
175
+ /**
176
+ * Calculates the shipping rate.
177
+ *
178
+ * @param array $package Order package.
179
+ */
180
+ public function calculate_shipping( $package = array() ) {
181
+ $api = new WC_Correios_Webservice_International( $this->id, $this->instance_id );
182
+
183
+ // Check if valid to be calculeted.
184
+ if ( ! in_array( $package['destination']['country'], $api->get_allowed_countries() ) ) {
185
+ return;
186
+ }
187
+
188
+ $shipping = $this->get_rate( $package );
189
+
190
+ if ( empty( $shipping->dados_postais->preco_postal ) ) {
191
+ return;
192
+ }
193
+
194
+ // Set the shipping rates.
195
+ $label = $this->title;
196
+ if ( 'yes' == $this->show_delivery_time ) {
197
+ $label .= ' (' . sanitize_text_field( (string) $shipping->dados_postais->prazo_entrega ) . ')';
198
+ }
199
+ $cost = sanitize_text_field( (float) $shipping->dados_postais->preco_postal );
200
+
201
+ // Exit if don't have price.
202
+ if ( 0 === intval( $cost ) ) {
203
+ return;
204
+ }
205
+
206
+ if ( 'yes' === $this->automatic_insurance ) {
207
+ $cost += sanitize_text_field( (float) $shipping->dados_postais->seguro_automatico );
208
+ }
209
+
210
+ // Apply fees.
211
+ $fee = $this->get_fee( wc_correios_normalize_price( $this->fee ), $cost );
212
+
213
+ // Create the rate and apply filters.
214
+ $rate = apply_filters( 'woocommerce_correios_' . $this->id . '_rate', array(
215
+ 'id' => $this->id . $this->instance_id,
216
+ 'label' => $label,
217
+ 'cost' => $cost + $fee,
218
+ ), $this->instance_id );
219
+
220
+ // Deprecated filter.
221
+ $rates = apply_filters( 'woocommerce_correios_shipping_methods', array( $rate ), $package );
222
+
223
+ // Add rate to WooCommerce.
224
+ $this->add_rate( $rates[0] );
225
+ }
226
+ }
includes/abstracts/abstract-wc-correios-shipping.php ADDED
@@ -0,0 +1,459 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Abstract Correios shipping method.
4
+ *
5
+ * @package WooCommerce_Correios/Abstracts
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * Default Correios shipping method abstract class.
16
+ *
17
+ * This is a abstract method with default options for all methods.
18
+ */
19
+ abstract class WC_Correios_Shipping extends WC_Shipping_Method {
20
+
21
+ /**
22
+ * Service code.
23
+ *
24
+ * @var string
25
+ */
26
+ protected $code = '';
27
+
28
+ /**
29
+ * Corporate code.
30
+ *
31
+ * @var string
32
+ */
33
+ protected $corporate_code = '';
34
+
35
+ /**
36
+ * Initialize the Correios shipping method.
37
+ *
38
+ * @param int $instance_id Shipping zone instance ID.
39
+ */
40
+ public function __construct( $instance_id = 0 ) {
41
+ $this->instance_id = absint( $instance_id );
42
+ $this->method_description = sprintf( __( '%s is a shipping method from Correios.', 'woocommerce-correios' ), $this->method_title );
43
+ $this->supports = array(
44
+ 'shipping-zones',
45
+ 'instance-settings',
46
+ );
47
+
48
+ // Load the form fields.
49
+ $this->init_form_fields();
50
+
51
+ // Define user set variables.
52
+ $this->enabled = $this->get_option( 'enabled' );
53
+ $this->title = $this->get_option( 'title' );
54
+ $this->origin_postcode = $this->get_option( 'origin_postcode' );
55
+ $this->show_delivery_time = $this->get_option( 'show_delivery_time' );
56
+ $this->additional_time = $this->get_option( 'additional_time' );
57
+ $this->fee = $this->get_option( 'fee' );
58
+ $this->receipt_notice = $this->get_option( 'receipt_notice' );
59
+ $this->own_hands = $this->get_option( 'own_hands' );
60
+ $this->declare_value = $this->get_option( 'declare_value' );
61
+ $this->custom_code = $this->get_option( 'custom_code' );
62
+ $this->service_type = $this->get_option( 'service_type' );
63
+ $this->login = $this->get_option( 'login' );
64
+ $this->password = $this->get_option( 'password' );
65
+ $this->minimum_height = $this->get_option( 'minimum_height' );
66
+ $this->minimum_width = $this->get_option( 'minimum_width' );
67
+ $this->minimum_length = $this->get_option( 'minimum_length' );
68
+ $this->debug = $this->get_option( 'debug' );
69
+
70
+ // Active logs.
71
+ if ( 'yes' == $this->debug ) {
72
+ $this->log = new WC_Logger();
73
+ }
74
+
75
+ // Save admin options.
76
+ add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
77
+ }
78
+
79
+ /**
80
+ * Get log.
81
+ *
82
+ * @return string
83
+ */
84
+ protected function get_log_link() {
85
+ if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.2', '>=' ) ) {
86
+ return ' <a href="' . esc_url( admin_url( 'admin.php?page=wc-status&tab=logs&log_file=' . esc_attr( $this->id ) . '-' . sanitize_file_name( wp_hash( $this->id ) ) . '.log' ) ) . '">' . __( 'View logs.', 'woocommerce-correios' ) . '</a>';
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Get behavior options.
92
+ *
93
+ * @return array
94
+ */
95
+ protected function get_behavior_options() {
96
+ return array();
97
+ }
98
+
99
+ /**
100
+ * Admin options fields.
101
+ */
102
+ public function init_form_fields() {
103
+ $this->instance_form_fields = array();
104
+
105
+ $this->instance_form_fields['enabled'] = array(
106
+ 'title' => __( 'Enable/Disable', 'woocommerce-correios' ),
107
+ 'type' => 'checkbox',
108
+ 'label' => __( 'Enable this shipping method', 'woocommerce-correios' ),
109
+ 'default' => 'yes',
110
+ );
111
+ $this->instance_form_fields['title'] = array(
112
+ 'title' => __( 'Title', 'woocommerce-correios' ),
113
+ 'type' => 'text',
114
+ 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-correios' ),
115
+ 'desc_tip' => true,
116
+ 'default' => $this->method_title,
117
+ );
118
+ $this->instance_form_fields['behavior_options'] = array(
119
+ 'title' => __( 'Behavior Options', 'woocommerce-correios' ),
120
+ 'type' => 'title',
121
+ 'default' => '',
122
+ );
123
+ $this->instance_form_fields['origin_postcode'] = array(
124
+ 'title' => __( 'Origin Postcode', 'woocommerce-correios' ),
125
+ 'type' => 'text',
126
+ 'description' => __( 'The postcode of the location your packages are delivered from.', 'woocommerce-correios' ),
127
+ 'desc_tip' => true,
128
+ 'placeholder' => '00000-000',
129
+ 'default' => '',
130
+ );
131
+ $this->instance_form_fields['show_delivery_time'] = array(
132
+ 'title' => __( 'Delivery Time', 'woocommerce-correios' ),
133
+ 'type' => 'checkbox',
134
+ 'label' => __( 'Show estimated delivery time', 'woocommerce-correios' ),
135
+ 'description' => __( 'Display the estimated delivery time in working days.', 'woocommerce-correios' ),
136
+ 'desc_tip' => true,
137
+ 'default' => 'no',
138
+ );
139
+ $this->instance_form_fields['additional_time'] = array(
140
+ 'title' => __( 'Additional Days', 'woocommerce-correios' ),
141
+ 'type' => 'text',
142
+ 'description' => __( 'Additional working days to the estimated delivery.', 'woocommerce-correios' ),
143
+ 'desc_tip' => true,
144
+ 'default' => '0',
145
+ 'placeholder' => '0',
146
+ );
147
+ $this->instance_form_fields['fee'] = array(
148
+ 'title' => __( 'Handling Fee', 'woocommerce-correios' ),
149
+ 'type' => 'price',
150
+ 'description' => __( 'Enter an amount, e.g. 2.50, or a percentage, e.g. 5%. Leave blank to disable.', 'woocommerce-correios' ),
151
+ 'desc_tip' => true,
152
+ 'placeholder' => '0.00',
153
+ 'default' => '',
154
+ );
155
+ $this->instance_form_fields['optional_services'] = array(
156
+ 'title' => __( 'Optional Services', 'woocommerce-correios' ),
157
+ 'type' => 'title',
158
+ 'description' => __( 'Use these options to add the value of each service provided by the Correios.', 'woocommerce-correios' ),
159
+ 'default' => '',
160
+ );
161
+ $this->instance_form_fields['receipt_notice'] = array(
162
+ 'title' => __( 'Receipt Notice', 'woocommerce-correios' ),
163
+ 'type' => 'checkbox',
164
+ 'label' => __( 'Enable receipt notice', 'woocommerce-correios' ),
165
+ 'description' => __( 'This controls whether to add costs of the receipt notice service.', 'woocommerce-correios' ),
166
+ 'desc_tip' => true,
167
+ 'default' => 'no',
168
+ );
169
+ $this->instance_form_fields['own_hands'] = array(
170
+ 'title' => __( 'Own Hands', 'woocommerce-correios' ),
171
+ 'type' => 'checkbox',
172
+ 'label' => __( 'Enable own hands', 'woocommerce-correios' ),
173
+ 'description' => __( 'This controls whether to add costs of the own hands service', 'woocommerce-correios' ),
174
+ 'desc_tip' => true,
175
+ 'default' => 'no',
176
+ );
177
+ $this->instance_form_fields['declare_value'] = array(
178
+ 'title' => __( 'Declare Value for Insurance', 'woocommerce-correios' ),
179
+ 'type' => 'checkbox',
180
+ 'label' => __( 'Enable declared value', 'woocommerce-correios' ),
181
+ 'description' => __( 'This controls if the price of the package must be declared for insurance purposes.', 'woocommerce-correios' ),
182
+ 'desc_tip' => true,
183
+ 'default' => 'yes',
184
+ );
185
+ $this->instance_form_fields['service_options'] = array(
186
+ 'title' => __( 'Service Options', 'woocommerce-correios' ),
187
+ 'type' => 'title',
188
+ 'default' => '',
189
+ );
190
+ $this->instance_form_fields['custom_code'] = array(
191
+ 'title' => __( 'Service Code', 'woocommerce-correios' ),
192
+ 'type' => 'text',
193
+ 'description' => __( 'Service code, use this for custom codes.', 'woocommerce-correios' ),
194
+ 'desc_tip' => true,
195
+ 'placeholder' => $this->code,
196
+ 'default' => '',
197
+ );
198
+ $this->instance_form_fields['service_type'] = array(
199
+ 'title' => __( 'Service Type', 'woocommerce-correios' ),
200
+ 'type' => 'select',
201
+ 'description' => __( 'Choose between conventional or corporate service.', 'woocommerce-correios' ),
202
+ 'desc_tip' => true,
203
+ 'default' => 'conventional',
204
+ 'class' => 'wc-enhanced-select',
205
+ 'options' => array(
206
+ 'conventional' => __( 'Conventional', 'woocommerce-correios' ),
207
+ 'corporate' => __( 'Corporate', 'woocommerce-correios' ),
208
+ ),
209
+ );
210
+ $this->instance_form_fields['login'] = array(
211
+ 'title' => __( 'Administrative Code', 'woocommerce-correios' ),
212
+ 'type' => 'text',
213
+ 'description' => __( 'Your Correios login. It\'s usually your CNPJ.', 'woocommerce-correios' ),
214
+ 'desc_tip' => true,
215
+ 'default' => '',
216
+ );
217
+ $this->instance_form_fields['password'] = array(
218
+ 'title' => __( 'Administrative Password', 'woocommerce-correios' ),
219
+ 'type' => 'text',
220
+ 'description' => __( 'Your Correios password.', 'woocommerce-correios' ),
221
+ 'desc_tip' => true,
222
+ 'default' => '',
223
+ );
224
+ $this->instance_form_fields['package_standard'] = array(
225
+ 'title' => __( 'Package Standard', 'woocommerce-correios' ),
226
+ 'type' => 'title',
227
+ 'description' => __( 'Minimum measure for your shipping packages.', 'woocommerce-correios' ),
228
+ 'default' => '',
229
+ );
230
+ $this->instance_form_fields['minimum_height'] = array(
231
+ 'title' => __( 'Minimum Height', 'woocommerce-correios' ),
232
+ 'type' => 'text',
233
+ 'description' => __( 'Minimum height of your shipping packages. Correios needs at least 2cm.', 'woocommerce-correios' ),
234
+ 'desc_tip' => true,
235
+ 'default' => '2',
236
+ );
237
+ $this->instance_form_fields['minimum_width'] = array(
238
+ 'title' => __( 'Minimum Width', 'woocommerce-correios' ),
239
+ 'type' => 'text',
240
+ 'description' => __( 'Minimum width of your shipping packages. Correios needs at least 11cm.', 'woocommerce-correios' ),
241
+ 'desc_tip' => true,
242
+ 'default' => '11',
243
+ );
244
+ $this->instance_form_fields['minimum_length'] = array(
245
+ 'title' => __( 'Minimum Length', 'woocommerce-correios' ),
246
+ 'type' => 'text',
247
+ 'description' => __( 'Minimum length of your shipping packages. Correios needs at least 16cm.', 'woocommerce-correios' ),
248
+ 'desc_tip' => true,
249
+ 'default' => '16',
250
+ );
251
+ $this->instance_form_fields['testing'] = array(
252
+ 'title' => __( 'Testing', 'woocommerce-correios' ),
253
+ 'type' => 'title',
254
+ 'default' => '',
255
+ );
256
+ $this->instance_form_fields['debug'] = array(
257
+ 'title' => __( 'Debug Log', 'woocommerce-correios' ),
258
+ 'type' => 'checkbox',
259
+ 'label' => __( 'Enable logging', 'woocommerce-correios' ),
260
+ 'default' => 'no',
261
+ 'description' => sprintf( __( 'Log %s events, such as WebServices requests.', 'woocommerce-correios' ), $this->method_title ) . $this->get_log_link(),
262
+ );
263
+ }
264
+
265
+ /**
266
+ * Correios options page.
267
+ */
268
+ public function admin_options() {
269
+ include WC_Correios::get_plugin_path() . 'includes/admin/views/html-admin-shipping-method-settings.php';
270
+ }
271
+
272
+ /**
273
+ * Get Correios service code.
274
+ *
275
+ * @return string
276
+ */
277
+ public function get_code() {
278
+ if ( ! empty( $this->custom_code ) ) {
279
+ $code = $this->custom_code;
280
+ } elseif ( $this->is_corporate() && ! empty( $this->corporate_code ) ) {
281
+ $code = $this->corporate_code;
282
+ } else {
283
+ $code = $this->code;
284
+ }
285
+
286
+ return apply_filters( 'woocommerce_correios_shipping_method_code', $code, $this->id, $this->instance_id );
287
+ }
288
+
289
+ /**
290
+ * Check if need to use corporate services.
291
+ *
292
+ * @return bool
293
+ */
294
+ protected function is_corporate() {
295
+ return 'corporate' === $this->service_type;
296
+ }
297
+
298
+ /**
299
+ * Get login.
300
+ *
301
+ * @return string
302
+ */
303
+ public function get_login() {
304
+ return $this->is_corporate() ? $this->login : '';
305
+ }
306
+
307
+ /**
308
+ * Get password.
309
+ *
310
+ * @return string
311
+ */
312
+ public function get_password() {
313
+ return $this->is_corporate() ? $this->password : '';
314
+ }
315
+
316
+ /**
317
+ * Get cart total.
318
+ *
319
+ * @return float
320
+ */
321
+ protected function get_cart_total() {
322
+ if ( ! WC()->cart->prices_include_tax ) {
323
+ return WC()->cart->cart_contents_total;
324
+ }
325
+
326
+ return WC()->cart->cart_contents_total + WC()->cart->tax_total;
327
+ }
328
+
329
+ /**
330
+ * Get shipping rate.
331
+ *
332
+ * @param array $package Order package.
333
+ *
334
+ * @return SimpleXMLElement
335
+ */
336
+ protected function get_rate( $package ) {
337
+ $api = new WC_Correios_Webservice( $this->id, $this->instance_id );
338
+ $api->set_debug( $this->debug );
339
+ $api->set_service( $this->get_code() );
340
+ $api->set_package( $package );
341
+ $api->set_origin_postcode( $this->origin_postcode );
342
+ $api->set_destination_postcode( $package['destination']['postcode'] );
343
+
344
+ if ( 'yes' === $this->declare_value ) {
345
+ $api->set_declared_value( $this->get_cart_total() );
346
+ }
347
+
348
+ $api->set_own_hands( 'yes' === $this->own_hands ? 'S' : 'N' );
349
+ $api->set_receipt_notice( 'yes' === $this->receipt_notice ? 'S' : 'N' );
350
+
351
+ $api->set_login( $this->get_login() );
352
+ $api->set_password( $this->get_password() );
353
+
354
+ $api->set_minimum_height( $this->minimum_height );
355
+ $api->set_minimum_width( $this->minimum_width );
356
+ $api->set_minimum_length( $this->minimum_length );
357
+
358
+ $shipping = $api->get_shipping();
359
+
360
+ return $shipping;
361
+ }
362
+
363
+ /**
364
+ * Get additional time.
365
+ *
366
+ * @param array $package Package data.
367
+ *
368
+ * @return array
369
+ */
370
+ protected function get_additional_time( $package = array() ) {
371
+ return apply_filters( 'woocommerce_correios_shipping_additional_time', $this->additional_time, $package );
372
+ }
373
+
374
+ /**
375
+ * Get accepted error codes.
376
+ *
377
+ * @return array
378
+ */
379
+ protected function get_accepted_error_codes() {
380
+ $codes = apply_filters( 'woocommerce_correios_accepted_error_codes', array( '-33', '-3', '010' ) );
381
+ $codes[] = '0';
382
+
383
+ return $codes;
384
+ }
385
+
386
+ /**
387
+ * Get shipping method label.
388
+ *
389
+ * @param int $days Days to deliver.
390
+ * @param array $package Package data.
391
+ *
392
+ * @return string
393
+ */
394
+ protected function get_shipping_method_label( $days, $package ) {
395
+ if ( 'yes' == $this->show_delivery_time ) {
396
+ return wc_correios_get_estimating_delivery( $this->title, $days, $this->get_additional_time( $package ) );
397
+ }
398
+
399
+ return $this->title;
400
+ }
401
+
402
+ /**
403
+ * Calculates the shipping rate.
404
+ *
405
+ * @param array $package Order package.
406
+ */
407
+ public function calculate_shipping( $package = array() ) {
408
+ // Check if valid to be calculeted.
409
+ if ( '' === $package['destination']['postcode'] || 'BR' !== $package['destination']['country'] ) {
410
+ return;
411
+ }
412
+
413
+ $shipping = $this->get_rate( $package );
414
+
415
+ if ( ! isset( $shipping->Erro ) ) {
416
+ return;
417
+ }
418
+
419
+ $error_number = (string) $shipping->Erro;
420
+
421
+ // Exit if have errors.
422
+ if ( ! in_array( $error_number, $this->get_accepted_error_codes() ) ) {
423
+ return;
424
+ }
425
+
426
+ // Display Correios errors.
427
+ $error_message = wc_correios_get_error_message( $error_number );
428
+ if ( '' != $error_message ) {
429
+ $notice_type = ( '010' == $error_number ) ? 'notice' : 'error';
430
+ $notice = '<strong>' . __( $this->title, 'woocommerce-correios' ) . ':</strong> ' . esc_html( $error_message );
431
+ wc_add_notice( $notice, $notice_type );
432
+ }
433
+
434
+ // Set the shipping rates.
435
+ $label = $this->get_shipping_method_label( (int) $shipping->PrazoEntrega, $package );
436
+ $cost = wc_correios_normalize_price( esc_attr( (string) $shipping->Valor ) );
437
+
438
+ // Exit if don't have price.
439
+ if ( 0 === intval( $cost ) ) {
440
+ return;
441
+ }
442
+
443
+ // Apply fees.
444
+ $fee = $this->get_fee( wc_correios_normalize_price( $this->fee ), $cost );
445
+
446
+ // Create the rate and apply filters.
447
+ $rate = apply_filters( 'woocommerce_correios_' . $this->id . '_rate', array(
448
+ 'id' => $this->id . $this->instance_id,
449
+ 'label' => $label,
450
+ 'cost' => $cost + $fee,
451
+ ), $this->instance_id );
452
+
453
+ // Deprecated filter.
454
+ $rates = apply_filters( 'woocommerce_correios_shipping_methods', array( $rate ), $package );
455
+
456
+ // Add rate to WooCommerce.
457
+ $this->add_rate( $rates[0] );
458
+ }
459
+ }
includes/admin/class-wc-correios-admin-orders.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Admin orders actions.
4
+ *
5
+ * @package WooCommerce_Correios/Admin/Orders
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * Correios orders.
16
+ */
17
+ class WC_Correios_Admin_Orders {
18
+
19
+ /**
20
+ * Initialize the order actions.
21
+ */
22
+ public function __construct() {
23
+ add_action( 'add_meta_boxes', array( $this, 'register_metabox' ) );
24
+ add_action( 'woocommerce_process_shop_order_meta', array( $this, 'save_tracking_code' ) );
25
+ }
26
+
27
+ /**
28
+ * Register tracking code metabox.
29
+ */
30
+ public function register_metabox() {
31
+ add_meta_box(
32
+ 'wc_correios',
33
+ 'Correios',
34
+ array( $this, 'metabox_content' ),
35
+ 'shop_order',
36
+ 'side',
37
+ 'default'
38
+ );
39
+ }
40
+
41
+ /**
42
+ * Tracking code metabox content.
43
+ *
44
+ * @param WC_Post $post Post data.
45
+ */
46
+ public function metabox_content( $post ) {
47
+ echo '<label for="correios_tracking">' . esc_html__( 'Tracking code:', 'woocommerce-correios' ) . '</label><br />';
48
+ echo '<input type="text" id="correios_tracking" name="correios_tracking" value="' . esc_attr( get_post_meta( $post->ID, '_correios_tracking_code', true ) ) . '" style="width: 100%;" />';
49
+ }
50
+
51
+ /**
52
+ * Save tracking code.
53
+ *
54
+ * @param int $post_id Current post type ID.
55
+ */
56
+ public function save_tracking_code( $post_id ) {
57
+ if ( empty( $_POST['woocommerce_meta_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['woocommerce_meta_nonce'] ) ), 'woocommerce_save_data' ) ) {
58
+ return;
59
+ }
60
+
61
+ if ( isset( $_POST['correios_tracking'] ) ) {
62
+ wc_correios_update_tracking_code( $post_id, wp_unslash( $_POST['correios_tracking'] ) );
63
+ }
64
+ }
65
+ }
66
+
67
+ new WC_Correios_Admin_Orders();
includes/admin/views/html-admin-help-message.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Admin help message.
4
+ *
5
+ * @package WooCommerce_Correios/Admin/Settings
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+ if ( apply_filters( 'woocommerce_correios_help_message', true ) ) : ?>
13
+ <div class="updated woocommerce-message inline">
14
+ <p><?php echo esc_html( sprintf( __( 'Help us keep the %s plugin free making a donation or rate &#9733;&#9733;&#9733;&#9733;&#9733; on WordPress.org. Thank you in advance!', 'woocommerce-correios' ), __( 'WooCommerce Correios', 'woocommerce-correios' ) ) ); ?></p>
15
+ <p><a href="http://claudiosmweb.com/doacoes/" target="_blank" class="button button-primary"><?php esc_html_e( 'Make a donation', 'woocommerce-correios' ); ?></a> <a href="https://wordpress.org/support/view/plugin-reviews/woocommerce-correios?filter=5#postform" target="_blank" class="button button-secondary"><?php esc_html_e( 'Make a review', 'woocommerce-correios' ); ?></a></p>
16
+ </div>
17
+ <?php endif;
includes/admin/views/html-admin-missing-dependencies.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Missing dependencies notice.
4
+ *
5
+ * @package WooCommerce_Correios/Admin/Notices
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+ $is_installed = false;
13
+
14
+ if ( function_exists( 'get_plugins' ) ) {
15
+ $all_plugins = get_plugins();
16
+ $is_installed = ! empty( $all_plugins['woocommerce/woocommerce.php'] );
17
+ }
18
+
19
+ ?>
20
+
21
+ <div class="error">
22
+ <p><strong><?php esc_html_e( 'WooCommerce Correios', 'woocommerce-correios' ); ?></strong> <?php esc_html_e( 'depends on the last version of WooCommerce to work!', 'woocommerce-correios' ); ?></p>
23
+
24
+ <?php if ( $is_installed && current_user_can( 'install_plugins' ) ) : ?>
25
+ <p><a href="<?php echo esc_url( wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=woocommerce/woocommerce.php&plugin_status=active' ), 'activate-plugin_woocommerce/woocommerce.php' ) ); ?>" class="button button-primary"><?php esc_html_e( 'Active WooCommerce', 'woocommerce-correios' ); ?></a></p>
26
+ <?php else : ?>
27
+ <?php
28
+ if ( current_user_can( 'install_plugins' ) ) {
29
+ $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=woocommerce' ), 'install-plugin_woocommerce' );
30
+ } else {
31
+ $url = 'http://wordpress.org/plugins/woocommerce/';
32
+ }
33
+ ?>
34
+ <p><a href="<?php echo esc_url( $url ); ?>" class="button button-primary"><?php esc_html_e( 'Install WooCommerce', 'woocommerce-correios' ); ?></a></p>
35
+ <?php endif; ?>
36
+ </div>
includes/admin/views/html-admin-shipping-method-settings.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Shipping methods admin settings.
4
+ *
5
+ * @package WooCommerce_Correios/Admin/Settings
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+ $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
13
+ wp_enqueue_script( 'wc-correios', plugins_url( 'assets/js/admin/shipping-methods' . $suffix . '.js', WC_Correios::get_main_file() ), array( 'jquery' ), WC_Correios::VERSION, true );
14
+
15
+
16
+ $description = $this->get_method_description();
17
+
18
+ if ( ! empty( $this->more_link ) ) {
19
+ $description .= ' <a href="' . esc_url( $this->more_link ) . '">' . esc_html( sprintf( __( 'More about %s.', 'woocommerce-correios' ), $this->method_title ) ) . '</a>';
20
+ }
21
+
22
+ echo wp_kses_post( wpautop( $description ) );
23
+
24
+ include dirname( __FILE__ ) . '/html-admin-help-message.php';
25
+
26
+ echo $this->get_admin_options_html();
includes/class-wc-correios-autofill-addresses.php ADDED
@@ -0,0 +1,314 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Correios Autofill Addresses.
4
+ *
5
+ * @package WooCommerce_Correios/Classes/Autofill
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * Correios autofill addresses class.
16
+ */
17
+ class WC_Correios_Autofill_Addresses {
18
+
19
+ /**
20
+ * Table name.
21
+ *
22
+ * @var string
23
+ */
24
+ public static $table = 'correios_postcodes';
25
+
26
+ /**
27
+ * Ajax endpoint.
28
+ *
29
+ * @var string
30
+ */
31
+ protected $ajax_endpoint = 'correios_autofill_address';
32
+
33
+ /**
34
+ * Addresses webservice URL.
35
+ *
36
+ * @var string
37
+ */
38
+ private $_webservice_url = 'https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl';
39
+
40
+ /**
41
+ * Initialize actions.
42
+ */
43
+ public function __construct() {
44
+ add_action( 'init', array( $this, 'init' ) );
45
+ }
46
+
47
+ /**
48
+ * Init autofill.
49
+ */
50
+ public function init() {
51
+ if ( apply_filters( 'woocommerce_correios_enable_autofill_addresses', false ) ) {
52
+ $this->maybe_install();
53
+
54
+ add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
55
+ add_action( 'wc_ajax_' . $this->ajax_endpoint, array( $this, 'ajax_autofill' ) );
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Get the addresses webservice URL.
61
+ *
62
+ * @return string
63
+ */
64
+ protected function get_tracking_addresses_webservice_url() {
65
+ return apply_filters( 'woocommerce_correios_addresses_webservice_url', $this->_webservice_url );
66
+ }
67
+
68
+ /**
69
+ * Logger.
70
+ *
71
+ * @param string $data Data to log.
72
+ */
73
+ protected function logger( $data ) {
74
+ if ( apply_filters( 'woocommerce_correios_enable_autofill_addresses_debug', false ) ) {
75
+ $logger = new WC_Logger();
76
+ $logger->add( 'correios-autofill-addresses', $data );
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Get validity.
82
+ *
83
+ * @return string
84
+ */
85
+ protected function get_validity() {
86
+ return apply_filters( 'woocommerce_correios_autofill_addresses_validity', 'forever' );
87
+ }
88
+
89
+ /**
90
+ * Get address by postcode.
91
+ *
92
+ * @param string $postcode
93
+ *
94
+ * @return stdClass
95
+ */
96
+ protected function get_address( $postcode ) {
97
+ global $wpdb;
98
+
99
+ $table = $wpdb->prefix . self::$table;
100
+ $address = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table WHERE postcode = %s;", $postcode ) );
101
+
102
+ if ( is_wp_error( $address ) || is_null( $address ) ) {
103
+ $address = $this->fetch_address( $postcode );
104
+
105
+ if ( ! is_null( $address ) ) {
106
+ $this->save_address( (array) $address );
107
+ }
108
+ } elseif ( $this->check_if_expired( $address->last_query ) ) {
109
+ $_address = $this->fetch_address( $postcode );
110
+
111
+ if ( ! is_null( $_address ) ) {
112
+ $address = $_address;
113
+ $this->update_address( (array) $address );
114
+ }
115
+ }
116
+
117
+ return $address;
118
+ }
119
+
120
+ /**
121
+ * Check if postcode is expired.
122
+ *
123
+ * @param string $last_query
124
+ * @return bool
125
+ */
126
+ protected function check_if_expired( $last_query ) {
127
+ $validity = $this->get_validity();
128
+
129
+ if ( 'forever' !== $validity && strtotime( '+' . $validity . ' months', strtotime( $last_query ) ) < current_time( 'timestamp' ) ) {
130
+ return true;
131
+ }
132
+
133
+ return false;
134
+ }
135
+
136
+ /**
137
+ * Insert an address.
138
+ *
139
+ * @param array $address
140
+ *
141
+ * @return bool
142
+ */
143
+ protected function save_address( $address ) {
144
+ global $wpdb;
145
+
146
+ $default = array(
147
+ 'postcode' => '',
148
+ 'address' => '',
149
+ 'city' => '',
150
+ 'neighborhood' => '',
151
+ 'state' => '',
152
+ 'last_query' => current_time( 'mysql' ),
153
+ );
154
+
155
+ $address = wp_parse_args( $address, $default );
156
+
157
+ $result = $wpdb->insert(
158
+ $wpdb->prefix . self::$table,
159
+ $address,
160
+ array( '%s', '%s', '%s', '%s', '%s', '%s' )
161
+ );
162
+
163
+ return false !== $result;
164
+ }
165
+
166
+ /**
167
+ * Delete an address from database.
168
+ */
169
+ protected function delete_address( $postcode ) {
170
+ global $wpdb;
171
+
172
+ $wpdb->delete( $wpdb->prefix . self::$table, array( 'postcode' => $postcode ), array( '%s' ) );
173
+ }
174
+
175
+ /**
176
+ * Update an address.
177
+ *
178
+ * @param array $address
179
+ *
180
+ * @return bool
181
+ */
182
+ protected function update_address( $address ) {
183
+ $this->delete_address( $address['postcode'] );
184
+
185
+ return $this->save_address( $address );
186
+ }
187
+
188
+ /**
189
+ * Fetch an address from Correios Webservices.
190
+ *
191
+ * @param string $postcode
192
+ * @return stdClass
193
+ */
194
+ protected function fetch_address( $postcode ) {
195
+ include_once dirname( __FILE__ ) . '/class-wc-correios-soap-client.php';
196
+
197
+ $this->logger( sprintf( 'Fetching address for "%s" on Correios Webservices...', $postcode ) );
198
+
199
+ $address = null;
200
+
201
+ try {
202
+ $soap = new WC_Correios_Soap_Client( $this->get_tracking_addresses_webservice_url() );
203
+ $response = $soap->consultaCEP( array( 'cep' => $postcode ) );
204
+ $data = $response->return;
205
+ $address = new stdClass;
206
+
207
+ $address->postcode = $data->cep;
208
+ $address->address = $data->end;
209
+ $address->city = $data->cidade;
210
+ $address->neighborhood = $data->bairro;
211
+ $address->state = $data->uf;
212
+ $address->last_query = current_time( 'mysql' );
213
+ } catch ( Exception $e ) {
214
+ $this->logger( sprintf( 'An error occurred while trying to fetch address for "%s": %s', $postcode, $e->getMessage() ) );
215
+ }
216
+
217
+ if ( ! is_null( $address ) ) {
218
+ $this->logger( sprintf( 'Address for "%s" found successfully: %s', $postcode, print_r( $address, true ) ) );
219
+ }
220
+
221
+ return $address;
222
+ }
223
+
224
+ /**
225
+ * Frontend scripts.
226
+ */
227
+ public function frontend_scripts() {
228
+ if ( is_checkout() || is_account_page() ) {
229
+ $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
230
+
231
+ wp_enqueue_script( 'woocommerce-correios-autofill-addresses', plugins_url( 'assets/js/frontend/autofill-address' . $suffix . '.js', WC_Correios::get_main_file() ), array( 'jquery', 'jquery-blockui' ), WC_Correios::VERSION, true );
232
+
233
+ wp_localize_script(
234
+ 'woocommerce-correios-autofill-addresses',
235
+ 'WCCorreiosAutofillAddressParams',
236
+ array(
237
+ 'url' => WC_AJAX::get_endpoint( $this->ajax_endpoint ),
238
+ 'force' => apply_filters( 'woocommerce_correios_autofill_addresses_force_autofill', 'no' ),
239
+ )
240
+ );
241
+ }
242
+ }
243
+
244
+ /**
245
+ * Ajax autofill endpoint.
246
+ */
247
+ public function ajax_autofill() {
248
+ if ( empty( $_GET['postcode'] ) ) {
249
+ wp_send_json_error( array( 'message' => __( 'Missing postcode paramater.', 'woocommerce-correios' ) ) );
250
+ exit;
251
+ }
252
+
253
+ $postcode = wc_correios_sanitize_postcode( $_GET['postcode'] );
254
+
255
+ if ( empty( $postcode ) || 8 !== strlen( $postcode ) ) {
256
+ wp_send_json_error( array( 'message' => __( 'Invalid postcode.', 'woocommerce-correios' ) ) );
257
+ exit;
258
+ }
259
+
260
+ $address = $this->get_address( $postcode );
261
+
262
+ if ( is_null( $address ) ) {
263
+ wp_send_json_error( array( 'message' => __( 'Invalid postcode.', 'woocommerce-correios' ) ) );
264
+ exit;
265
+ }
266
+
267
+ // Unset ID and last_query.
268
+ unset( $address->ID );
269
+ unset( $address->last_query );
270
+
271
+ wp_send_json_success( $address );
272
+ }
273
+
274
+ /**
275
+ * Maybe install database.
276
+ */
277
+ public function maybe_install() {
278
+ $version = get_option( 'woocommerce_correios_autofill_addresses_db_version' );
279
+
280
+ if ( empty( $version ) ) {
281
+ self::create_database();
282
+
283
+ update_option( 'woocommerce_correios_autofill_addresses_db_version', '1.0.0' );
284
+ }
285
+ }
286
+
287
+ /**
288
+ * Create database.
289
+ */
290
+ public static function create_database() {
291
+ global $wpdb;
292
+
293
+ $charset_collate = $wpdb->get_charset_collate();
294
+ $table_name = $wpdb->prefix . self::$table;
295
+
296
+ $sql = "CREATE TABLE $table_name (
297
+ ID bigint(20) NOT NULL auto_increment,
298
+ postcode char(8) NOT NULL,
299
+ address longtext NULL,
300
+ city longtext NULL,
301
+ neighborhood longtext NULL,
302
+ state char(2) NULL,
303
+ last_query datetime NULL,
304
+ PRIMARY KEY (ID),
305
+ KEY postcode (postcode)
306
+ ) $charset_collate;";
307
+
308
+ require_once ABSPATH . 'wp-admin/includes/upgrade.php';
309
+
310
+ dbDelta( $sql );
311
+ }
312
+ }
313
+
314
+ new WC_Correios_Autofill_Addresses();
includes/class-wc-correios-install.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Correios integration with the REST API.
4
+ *
5
+ * @package WooCommerce_Correios/Classes
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit; // Exit if accessed directly.
12
+ }
13
+
14
+ /**
15
+ * WC_Correios_REST_API class.
16
+ */
17
+ class WC_Correios_Install {
18
+
19
+ /**
20
+ * Get version.
21
+ *
22
+ * @return string
23
+ */
24
+ private static function get_version() {
25
+ return get_option( 'woocommerce_correios_version' );
26
+ }
27
+
28
+ /**
29
+ * Update version.
30
+ */
31
+ private static function update_version() {
32
+ update_option( 'woocommerce_correios_version', WC_Correios::VERSION );
33
+ }
34
+
35
+ /**
36
+ * Upgrade to 3.0.0.
37
+ */
38
+ public static function upgrade_300() {
39
+ global $wpdb;
40
+
41
+ $version = self::get_version();
42
+
43
+ if ( empty( $version ) ) {
44
+ $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_correios_tracking_code' WHERE meta_key = 'correios_tracking';" );
45
+ }
46
+ }
47
+
48
+ /**
49
+ * Upgrade to 3.0.0 while using WooCommerce 2.6.0.
50
+ */
51
+ public static function upgrade_300_to_wc_260() {
52
+ if ( $old_options = get_option( 'woocommerce_correios_settings' ) ) {
53
+ if ( isset( $old_options['tracking_history'] ) ) {
54
+ $integration_options = get_option( 'woocommerce_correios-integration_settings', array(
55
+ 'general_options' => '',
56
+ 'tracking' => '',
57
+ 'enable_tracking' => 'no',
58
+ 'tracking_debug' => 'no',
59
+ ) );
60
+
61
+ // Update integration options.
62
+ $integration_options['enable_tracking'] = $old_options['tracking_history'];
63
+ update_option( 'woocommerce_correios-integration_settings', $integration_options );
64
+
65
+ // Update the old options.
66
+ unset( $old_options['tracking_history'] );
67
+ update_option( 'woocommerce_correios_settings', $old_options );
68
+ }
69
+
70
+ if ( 'no' === $old_options['enabled'] ) {
71
+ delete_option( 'woocommerce_correios_settings' );
72
+ }
73
+ }
74
+ }
75
+ }
includes/class-wc-correios-package.php ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Correios Package.
4
+ *
5
+ * @package WooCommerce_Correios/Classes
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit; // Exit if accessed directly.
12
+ }
13
+
14
+ /**
15
+ * WC_Correios_Package class.
16
+ */
17
+ class WC_Correios_Package {
18
+
19
+ /**
20
+ * Order package.
21
+ *
22
+ * @var array
23
+ */
24
+ protected $package = array();
25
+
26
+ /**
27
+ * Sets the package.
28
+ *
29
+ * @param array $package Package to calcule.
30
+ *
31
+ * @return array
32
+ */
33
+ public function __construct( $package = array() ) {
34
+ $this->package = $package;
35
+ }
36
+
37
+ /**
38
+ * Replace comma by dot.
39
+ *
40
+ * @param mixed $value Value to fix.
41
+ *
42
+ * @return mixed
43
+ */
44
+ private function fix_format( $value ) {
45
+ $value = str_replace( ',', '.', $value );
46
+
47
+ return $value;
48
+ }
49
+
50
+ /**
51
+ * Extracts the weight and dimensions from the package.
52
+ *
53
+ * @return array
54
+ */
55
+ protected function get_package_data() {
56
+ $count = 0;
57
+ $height = array();
58
+ $width = array();
59
+ $length = array();
60
+ $weight = array();
61
+
62
+ // Shipping per item.
63
+ foreach ( $this->package['contents'] as $item_id => $values ) {
64
+ $product = $values['data'];
65
+ $qty = $values['quantity'];
66
+
67
+ if ( $qty > 0 && $product->needs_shipping() ) {
68
+
69
+ $_height = wc_get_dimension( $this->fix_format( $product->height ), 'cm' );
70
+ $_width = wc_get_dimension( $this->fix_format( $product->width ), 'cm' );
71
+ $_length = wc_get_dimension( $this->fix_format( $product->length ), 'cm' );
72
+ $_weight = wc_get_weight( $this->fix_format( $product->weight ), 'kg' );
73
+
74
+ $height[ $count ] = $_height;
75
+ $width[ $count ] = $_width;
76
+ $length[ $count ] = $_length;
77
+ $weight[ $count ] = $_weight;
78
+
79
+ if ( $qty > 1 ) {
80
+ $n = $count;
81
+ for ( $i = 0; $i < $qty; $i++ ) {
82
+ $height[ $n ] = $_height;
83
+ $width[ $n ] = $_width;
84
+ $length[ $n ] = $_length;
85
+ $weight[ $n ] = $_weight;
86
+ $n++;
87
+ }
88
+ $count = $n;
89
+ }
90
+
91
+ $count++;
92
+ }
93
+ }
94
+
95
+ return array(
96
+ 'height' => array_values( $height ),
97
+ 'length' => array_values( $length ),
98
+ 'width' => array_values( $width ),
99
+ 'weight' => array_sum( $weight ),
100
+ );
101
+ }
102
+
103
+ /**
104
+ * Calculates the cubage of all products.
105
+ *
106
+ * @param array $height Package height.
107
+ * @param array $width Package width.
108
+ * @param array $length Package length.
109
+ *
110
+ * @return int
111
+ */
112
+ protected function cubage_total( $height, $width, $length ) {
113
+ // Sets the cubage of all products.
114
+ $all = array();
115
+ $total = 0;
116
+
117
+ for ( $i = 0; $i < count( $height ); $i++ ) {
118
+ $all[ $i ] = $height[ $i ] * $width[ $i ] * $length[ $i ];
119
+ }
120
+
121
+ foreach ( $all as $value ) {
122
+ $total += $value;
123
+ }
124
+
125
+ return $total;
126
+ }
127
+
128
+ /**
129
+ * Get the max values.
130
+ *
131
+ * @param array $height Package height.
132
+ * @param array $width Package width.
133
+ * @param array $length Package length.
134
+ *
135
+ * @return array
136
+ */
137
+ protected function get_max_values( $height, $width, $length ) {
138
+ $find = array(
139
+ 'height' => max( $height ),
140
+ 'width' => max( $width ),
141
+ 'length' => max( $length ),
142
+ );
143
+
144
+ return $find;
145
+ }
146
+
147
+ /**
148
+ * Calculates the square root of the scaling of all products.
149
+ *
150
+ * @param array $height Package height.
151
+ * @param array $width Package width.
152
+ * @param array $length Package length.
153
+ * @param array $max_values Package bigger values.
154
+ *
155
+ * @return float
156
+ */
157
+ protected function calculate_root( $height, $width, $length, $max_values ) {
158
+ $cubage_total = $this->cubage_total( $height, $width, $length );
159
+ $root = 0;
160
+
161
+ if ( 0 != $cubage_total ) {
162
+ // Dividing the value of scaling of all products.
163
+ // With the measured value of greater.
164
+ $division = $cubage_total / max( $max_values );
165
+ // Total square root.
166
+ $root = round( sqrt( $division ), 1 );
167
+ }
168
+
169
+ return $root;
170
+ }
171
+
172
+ /**
173
+ * Sets the final cubage.
174
+ *
175
+ * @param array $height Package height.
176
+ * @param array $width Package width.
177
+ * @param array $length Package length.
178
+ *
179
+ * @return array
180
+ */
181
+ protected function get_cubage( $height, $width, $length ) {
182
+ $cubage = array();
183
+ $max_values = $this->get_max_values( $height, $width, $length );
184
+ $root = $this->calculate_root( $height, $width, $length, $max_values );
185
+ $greatest = array_search( max( $max_values ), $max_values );
186
+
187
+ switch ( $greatest ) {
188
+ case 'height' :
189
+ $cubage = array(
190
+ 'height' => max( $height ),
191
+ 'width' => $root,
192
+ 'length' => $root,
193
+ );
194
+ break;
195
+ case 'width' :
196
+ $cubage = array(
197
+ 'height' => $root,
198
+ 'width' => max( $width ),
199
+ 'length' => $root,
200
+ );
201
+ break;
202
+ case 'length' :
203
+ $cubage = array(
204
+ 'height' => $root,
205
+ 'width' => $root,
206
+ 'length' => max( $length ),
207
+ );
208
+ break;
209
+
210
+ default :
211
+ $cubage = array(
212
+ 'height' => 0,
213
+ 'width' => 0,
214
+ 'length' => 0,
215
+ );
216
+ break;
217
+ }
218
+
219
+ return $cubage;
220
+ }
221
+
222
+ /**
223
+ * Get the package data.
224
+ *
225
+ * @return array
226
+ */
227
+ public function get_data() {
228
+ // Get the package data.
229
+ $data = apply_filters( 'woocommerce_correios_default_package', $this->get_package_data() );
230
+
231
+ if ( ! empty( $data['height'] ) && ! empty( $data['width'] ) && ! empty( $data['length'] ) ) {
232
+ $cubage = $this->get_cubage( $data['height'], $data['width'], $data['length'] );
233
+ } else {
234
+ $cubage = array(
235
+ 'height' => 0,
236
+ 'width' => 0,
237
+ 'length' => 0,
238
+ );
239
+ }
240
+
241
+ return array(
242
+ 'height' => apply_filters( 'woocommerce_correios_package_height', $cubage['height'] ),
243
+ 'width' => apply_filters( 'woocommerce_correios_package_width', $cubage['width'] ),
244
+ 'length' => apply_filters( 'woocommerce_correios_package_length', $cubage['length'] ),
245
+ 'weight' => apply_filters( 'woocommerce_correios_package_weight', $data['weight'] ),
246
+ );
247
+ }
248
+ }
includes/class-wc-correios-rest-api.php ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Correios integration with the REST API.
4
+ *
5
+ * @package WooCommerce_Correios/Classes
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit; // Exit if accessed directly.
12
+ }
13
+
14
+ /**
15
+ * WC_Correios_REST_API class.
16
+ */
17
+ class WC_Correios_REST_API {
18
+
19
+ /**
20
+ * Init REST API actions.
21
+ */
22
+ public function __construct() {
23
+ add_filter( 'woocommerce_api_order_response', array( $this, 'legacy_orders_response' ), 100, 3 );
24
+ add_filter( 'woocommerce_api_create_order', array( $this, 'legacy_orders_update' ), 100, 2 );
25
+ add_filter( 'woocommerce_api_edit_order', array( $this, 'legacy_orders_update' ), 100, 2 );
26
+ add_action( 'rest_api_init', array( $this, 'register_tracking_code' ), 100 );
27
+ }
28
+
29
+ /**
30
+ * Add the tracking code to the legacy WooCOmmerce REST API.
31
+ *
32
+ * @param array $data Endpoint response.
33
+ * @param WC_Order $order Order object.
34
+ * @param array $fields Fields filter.
35
+ *
36
+ * @return array
37
+ */
38
+ public function legacy_orders_response( $data, $order, $fields ) {
39
+ $data['correios_tracking_code'] = $order->correios_tracking_code;
40
+
41
+ if ( $fields ) {
42
+ $data = WC()->api->WC_API_Customers->filter_response_fields( $data, $order, $fields );
43
+ }
44
+
45
+ return $data;
46
+ }
47
+
48
+ /**
49
+ * Update tracking code using the legacy WooCOmmerce REST API.
50
+ *
51
+ * @param int $order_id Order ID.
52
+ * @param array $data Posted data.
53
+ */
54
+ public function legacy_orders_update( $order_id, $data ) {
55
+ if ( isset( $data['correios_tracking_code'] ) ) {
56
+ wc_correios_update_tracking_code( $order_id, $data['correios_tracking_code'] );
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Register tracking code field in WP REST API.
62
+ */
63
+ public function register_tracking_code() {
64
+ if ( ! function_exists( 'register_rest_field' ) ) {
65
+ return;
66
+ }
67
+
68
+ register_rest_field( 'shop_order',
69
+ 'correios_tracking_code',
70
+ array(
71
+ 'get_callback' => array( $this, 'get_tracking_code_callback' ),
72
+ 'update_callback' => array( $this, 'update_tracking_code_callback' ),
73
+ 'schema' => array(
74
+ 'description' => __( 'Correios tracking code.', 'woocommerce-correios' ),
75
+ 'type' => 'string',
76
+ 'context' => array( 'view', 'edit' ),
77
+ ),
78
+ )
79
+ );
80
+ }
81
+
82
+ /**
83
+ * Get tracking code callback.
84
+ *
85
+ * @param array $data Details of current response.
86
+ * @param string $field Name of field.
87
+ * @param WP_REST_Request $request Current request.
88
+ *
89
+ * @return string
90
+ */
91
+ function get_tracking_code_callback( $data, $field, $request ) {
92
+ return get_post_meta( $data['id'], '_' . $field, true );
93
+ }
94
+
95
+ /**
96
+ * Update tracking code callback.
97
+ *
98
+ * @param string $value The value of the field.
99
+ * @param WP_Post $object The object from the response.
100
+ *
101
+ * @return bool
102
+ */
103
+ function update_tracking_code_callback( $value, $object ) {
104
+ if ( ! $value || ! is_string( $value ) ) {
105
+ return;
106
+ }
107
+
108
+ return wc_correios_update_tracking_code( $object->ID, $value );
109
+ }
110
+ }
111
+
112
+ new WC_Correios_REST_API();
includes/class-wc-correios-soap-client.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Correios Soap Client.
4
+ *
5
+ * @package WooCommerce_Correios/Classes/Soap
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * WC_Correios_Soap_Client class.
16
+ */
17
+ class WC_Correios_Soap_Client extends SoapClient {
18
+
19
+ /**
20
+ * SoapClient construct.
21
+ *
22
+ * @param mixed $wsdl
23
+ */
24
+ public function __construct( $wsdl ) {
25
+ parent::__construct( $wsdl, array(
26
+ 'cache_wsdl' => WSDL_CACHE_NONE,
27
+ 'encoding' => 'UTF-8',
28
+ 'exceptions' => true,
29
+ 'stream_context' => $this->get_custom_stream_context(),
30
+ )
31
+ );
32
+ }
33
+
34
+ /**
35
+ * Get a custom stream context to improve performance.
36
+ *
37
+ * @return resource Of type stream-context.
38
+ */
39
+ private function get_custom_stream_context() {
40
+ return stream_context_create( array( 'http' => array( 'protocol_version' => '1.0', 'header' => 'Connection: Close' ) ) );
41
+ }
42
+ }
includes/class-wc-correios-tracking-history.php ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Correios Tracking History.
4
+ *
5
+ * @package WooCommerce_Correios/Classes/Tracking
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * Correios tracking history class.
16
+ */
17
+ class WC_Correios_Tracking_History {
18
+
19
+ /**
20
+ * Tracking webservice URL.
21
+ *
22
+ * @var string
23
+ */
24
+ private $_webservice_url = 'https://webservice.correios.com.br/service/rastro/Rastro.wsdl';
25
+
26
+ /**
27
+ * Initialize actions.
28
+ */
29
+ public function __construct() {
30
+ add_action( 'woocommerce_order_details_after_order_table', array( $this, 'view' ), 1 );
31
+ }
32
+
33
+ /**
34
+ * Get the tracking history webservice URL.
35
+ *
36
+ * @return string
37
+ */
38
+ protected function get_tracking_history_webservice_url() {
39
+ return apply_filters( 'woocommerce_correios_tracking_webservice_url', $this->_webservice_url );
40
+ }
41
+
42
+ /**
43
+ * Get user data.
44
+ *
45
+ * @return array
46
+ */
47
+ protected function get_user_data() {
48
+ $user_data = apply_filters( 'woocommerce_correios_tracking_user_data', array( 'login' => 'ECT', 'password' => 'SRO' ) );
49
+
50
+ return $user_data;
51
+ }
52
+
53
+ /**
54
+ * Logger.
55
+ *
56
+ * @param string $data Data to log.
57
+ */
58
+ protected function logger( $data ) {
59
+ if ( apply_filters( 'woocommerce_correios_enable_tracking_debug', false ) ) {
60
+ $logger = new WC_Logger();
61
+ $logger->add( 'correios-tracking-history', $data );
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Access API Correios.
67
+ *
68
+ * @param string $tracking_code Tracking code.
69
+ *
70
+ * @return array
71
+ */
72
+ protected function get_tracking_history( $tracking_code ) {
73
+ include_once dirname( __FILE__ ) . '/class-wc-correios-soap-client.php';
74
+
75
+ $this->logger( sprintf( 'Fetching tracking history for "%s" on Correios Webservices...', $tracking_code ) );
76
+
77
+ $events = null;
78
+ $user_data = $this->get_user_data();
79
+ $args = apply_filters( 'woocommerce_correios_tracking_history_webservice_args', array(
80
+ 'usuario' => $user_data['login'],
81
+ 'senha' => $user_data['password'],
82
+ 'tipo' => 'L', // L - List of objects, F - Object Range.
83
+ 'resultado' => 'T', // T - Returns all the object's events, U - Returns only last event object.
84
+ 'lingua' => '101',
85
+ 'objetos' => $tracking_code,
86
+ ) );
87
+
88
+ try {
89
+ $soap = new WC_Correios_Soap_Client( $this->get_tracking_history_webservice_url() );
90
+ $response = $soap->buscaEventos( $args );
91
+ $events = (array) $response->return->objeto->evento;
92
+ } catch ( Exception $e ) {
93
+ $this->logger( sprintf( 'An error occurred while trying to fetch the tracking history for "%s": %s', $tracking_code, $e->getMessage() ) );
94
+ }
95
+
96
+ if ( ! is_null( $events ) ) {
97
+ $this->logger( sprintf( 'Tracking history for "%s" found successfully: %s', $tracking_code, print_r( $events, true ) ) );
98
+ }
99
+
100
+ return apply_filters( 'woocommerce_correios_tracking_response', $events, $tracking_code );
101
+ }
102
+
103
+ /**
104
+ * Display the order tracking code in order details and the tracking history.
105
+ *
106
+ * @param WC_Order $order Order data.
107
+ */
108
+ public function view( $order ) {
109
+ $events = false;
110
+ $tracking_code = get_post_meta( $order->id, '_correios_tracking_code', true );
111
+
112
+ // Check if exist a tracking code for the order.
113
+ if ( ! $tracking_code ) {
114
+ return;
115
+ }
116
+
117
+ // Try to connect to Correios Webservices and get the tracking history.
118
+ if ( apply_filters( 'woocommerce_correios_enable_tracking_history', false ) ) {
119
+ $events = $this->get_tracking_history( $tracking_code );
120
+ }
121
+
122
+ // Display the right template for show the tracking code or tracking history.
123
+ if ( is_array( $events ) ) {
124
+ wc_get_template(
125
+ 'myaccount/tracking-history-table.php',
126
+ array(
127
+ 'events' => $events,
128
+ 'code' => $tracking_code,
129
+ ),
130
+ '',
131
+ WC_Correios::get_templates_path()
132
+ );
133
+ } else {
134
+ wc_get_template(
135
+ 'myaccount/tracking-code.php',
136
+ array(
137
+ 'code' => $tracking_code,
138
+ ),
139
+ '',
140
+ WC_Correios::get_templates_path()
141
+ );
142
+ }
143
+ }
144
+ }
145
+
146
+ new WC_Correios_Tracking_History();
includes/class-wc-correios-webservice-international.php ADDED
@@ -0,0 +1,652 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Correios Webservice International.
4
+ *
5
+ * @package WooCommerce_Correios/Classes/Webservice
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * Correios Webservice International integration class.
16
+ */
17
+ class WC_Correios_Webservice_International {
18
+
19
+ /**
20
+ * Webservice URL.
21
+ *
22
+ * @var string
23
+ */
24
+ private $_webservice = 'http://www2.correios.com.br/sistemas/efi/bb/Consulta.cfm?';
25
+
26
+ /**
27
+ * Shipping method ID.
28
+ *
29
+ * @var string
30
+ */
31
+ protected $id = '';
32
+
33
+ /**
34
+ * Shipping zone instance ID.
35
+ *
36
+ * @var int
37
+ */
38
+ protected $instance_id = 0;
39
+
40
+ /**
41
+ * IDs from Correios services.
42
+ *
43
+ * 110 - Mercadoria Expressa (EMS).
44
+ * 128 - Mercadoria Econômica.
45
+ * 209 - Leve Internacional.
46
+ *
47
+ * @var string
48
+ */
49
+ protected $service = '';
50
+
51
+ /**
52
+ * Destination country.
53
+ *
54
+ * @var string
55
+ */
56
+ protected $destination_country = '';
57
+
58
+ /**
59
+ * Origin location.
60
+ *
61
+ * @var string
62
+ */
63
+ protected $origin_location = '';
64
+
65
+ /**
66
+ * Origin state.
67
+ *
68
+ * @var string
69
+ */
70
+ protected $origin_state = '';
71
+
72
+ /**
73
+ * Package height.
74
+ *
75
+ * @var float
76
+ */
77
+ protected $height = 0;
78
+
79
+ /**
80
+ * Package width.
81
+ *
82
+ * @var float
83
+ */
84
+ protected $width = 0;
85
+
86
+ /**
87
+ * Package length.
88
+ *
89
+ * @var float
90
+ */
91
+ protected $length = 0;
92
+
93
+ /**
94
+ * Package weight.
95
+ *
96
+ * @var float
97
+ */
98
+ protected $weight = 0;
99
+
100
+ /**
101
+ * Declared value.
102
+ *
103
+ * @var string
104
+ */
105
+ protected $declared_value = '0';
106
+
107
+ /**
108
+ * Debug mode.
109
+ *
110
+ * @var string
111
+ */
112
+ protected $debug = 'no';
113
+
114
+ /**
115
+ * Initialize webservice.
116
+ *
117
+ * @param string $id
118
+ * @param int $instance_id
119
+ */
120
+ public function __construct( $id = 'correios', $instance_id = 0 ) {
121
+ $this->id = $id;
122
+ $this->instance_id = $instance_id;
123
+ $this->log = new WC_Logger();
124
+ }
125
+
126
+ /**
127
+ * Set the service.
128
+ *
129
+ * @param string $service Correios international service.
130
+ */
131
+ public function set_service( $service = '' ) {
132
+ $this->service = $service;
133
+ }
134
+
135
+ /**
136
+ * Set shipping package.
137
+ *
138
+ * @param array $package Shipping package.
139
+ */
140
+ public function set_package( $package = array() ) {
141
+ $package = new WC_Correios_Package( $package );
142
+
143
+ if ( ! is_null( $package ) ) {
144
+ $data = $package->get_data();
145
+
146
+ $this->set_height( $data['height'] );
147
+ $this->set_width( $data['width'] );
148
+ $this->set_length( $data['length'] );
149
+ $this->set_weight( $data['weight'] );
150
+ }
151
+
152
+ if ( 'yes' == $this->debug ) {
153
+ if ( ! empty( $data ) ) {
154
+ $data = array(
155
+ 'weight' => $this->get_weight(),
156
+ 'height' => $this->get_height(),
157
+ 'width' => $this->get_width(),
158
+ 'length' => $this->get_length(),
159
+ );
160
+ }
161
+
162
+ $this->log->add( $this->id, 'Weight and cubage of the order: ' . print_r( $data, true ) );
163
+ }
164
+ }
165
+
166
+ /**
167
+ * Set destination country.
168
+ *
169
+ * @param string $country Destination country.
170
+ */
171
+ public function set_destination_country( $country = '' ) {
172
+ $this->destination_country = $country;
173
+ }
174
+
175
+ /**
176
+ * Set origin location.
177
+ *
178
+ * @param string $location Origin location.
179
+ */
180
+ public function set_origin_location( $location = '' ) {
181
+ $this->origin_location = $location;
182
+ }
183
+
184
+ /**
185
+ * Set origin state.
186
+ *
187
+ * @param string $state Origin state.
188
+ */
189
+ public function set_origin_state( $state = '' ) {
190
+ $this->origin_state = $state;
191
+ }
192
+
193
+ /**
194
+ * Set shipping package height.
195
+ *
196
+ * @param float $height Shipping package height.
197
+ */
198
+ public function set_height( $height = 0 ) {
199
+ $this->height = (float) $height;
200
+ }
201
+
202
+ /**
203
+ * Set shipping package width.
204
+ *
205
+ * @param float $width Shipping package width.
206
+ */
207
+ public function set_width( $width = 0 ) {
208
+ $this->width = (float) $width;
209
+ }
210
+
211
+ /**
212
+ * Set shipping package length.
213
+ *
214
+ * @param float $length Shipping package length.
215
+ */
216
+ public function set_length( $length = 0 ) {
217
+ $this->length = (float) $length;
218
+ }
219
+
220
+ /**
221
+ * Set shipping package weight.
222
+ *
223
+ * @param float $weight Shipping package weight.
224
+ */
225
+ public function set_weight( $weight = 0 ) {
226
+ $this->weight = (float) $weight;
227
+ }
228
+
229
+ /**
230
+ * Set the debug mode.
231
+ *
232
+ * @param string $debug Yes or no.
233
+ */
234
+ public function set_debug( $debug = 'no' ) {
235
+ $this->debug = $debug;
236
+ }
237
+
238
+ /**
239
+ * Get webservice URL.
240
+ *
241
+ * @return string
242
+ */
243
+ public function get_webservice_url() {
244
+ return apply_filters( 'woocommerce_correios_webservice_international_url', $this->_webservice, $this->id, $this->instance_id );
245
+ }
246
+
247
+ /**
248
+ * Get allowed countries.
249
+ *
250
+ * @return string
251
+ */
252
+ public function get_allowed_countries() {
253
+ return apply_filters( 'woocommerce_correios_international_allowed_countries', array(
254
+ 'AD',
255
+ 'AE',
256
+ 'AF',
257
+ 'AG',
258
+ 'AI',
259
+ 'AL',
260
+ 'AM',
261
+ 'AN',
262
+ 'AO',
263
+ 'AR',
264
+ 'AS',
265
+ 'AT',
266
+ 'AU',
267
+ 'AW',
268
+ 'AZ',
269
+ 'BA',
270
+ 'BB',
271
+ 'BD',
272
+ 'BE',
273
+ 'BF',
274
+ 'BG',
275
+ 'BH',
276
+ 'BI',
277
+ 'BJ',
278
+ 'BM',
279
+ 'BN',
280
+ 'BO',
281
+ 'BS',
282
+ 'BT',
283
+ 'BW',
284
+ 'BY',
285
+ 'BZ',
286
+ 'CA',
287
+ 'CC',
288
+ 'CD',
289
+ 'CF',
290
+ 'CG',
291
+ 'CH',
292
+ 'CI',
293
+ 'CK',
294
+ 'CL',
295
+ 'CM',
296
+ 'CN',
297
+ 'CO',
298
+ 'CR',
299
+ 'CU',
300
+ 'CV',
301
+ 'CX',
302
+ 'CY',
303
+ 'CZ',
304
+ 'DE',
305
+ 'DJ',
306
+ 'DK',
307
+ 'DM',
308
+ 'DO',
309
+ 'DZ',
310
+ 'EC',
311
+ 'EE',
312
+ 'EG',
313
+ 'EH',
314
+ 'ER',
315
+ 'ES',
316
+ 'ET',
317
+ 'FI',
318
+ 'FJ',
319
+ 'FK',
320
+ 'FM',
321
+ 'FO',
322
+ 'FR',
323
+ 'GA',
324
+ 'GB',
325
+ 'GD',
326
+ 'GE',
327
+ 'GF',
328
+ 'GG',
329
+ 'GH',
330
+ 'GI',
331
+ 'GL',
332
+ 'GM',
333
+ 'GN',
334
+ 'GP',
335
+ 'GQ',
336
+ 'GR',
337
+ 'GS',
338
+ 'GT',
339
+ 'GU',
340
+ 'GW',
341
+ 'GY',
342
+ 'HK',
343
+ 'HN',
344
+ 'HR',
345
+ 'HT',
346
+ 'HU',
347
+ 'ID',
348
+ 'IE',
349
+ 'IL',
350
+ 'IM',
351
+ 'IN',
352
+ 'IQ',
353
+ 'IR',
354
+ 'IS',
355
+ 'IT',
356
+ 'JE',
357
+ 'JM',
358
+ 'JO',
359
+ 'JP',
360
+ 'KE',
361
+ 'KG',
362
+ 'KH',
363
+ 'KI',
364
+ 'KM',
365
+ 'KN',
366
+ 'KP',
367
+ 'KR',
368
+ 'KW',
369
+ 'KY',
370
+ 'KZ',
371
+ 'LA',
372
+ 'LB',
373
+ 'LC',
374
+ 'LI',
375
+ 'LK',
376
+ 'LR',
377
+ 'LS',
378
+ 'LT',
379
+ 'LU',
380
+ 'LV',
381
+ 'LY',
382
+ 'MA',
383
+ 'MC',
384
+ 'MD',
385
+ 'ME',
386
+ 'MG',
387
+ 'MH',
388
+ 'MK',
389
+ 'ML',
390
+ 'MM',
391
+ 'MN',
392
+ 'MO',
393
+ 'MP',
394
+ 'MQ',
395
+ 'MR',
396
+ 'MS',
397
+ 'MT',
398
+ 'MU',
399
+ 'MV',
400
+ 'MW',
401
+ 'MX',
402
+ 'MY',
403
+ 'MZ',
404
+ 'NA',
405
+ 'NC',
406
+ 'NE',
407
+ 'NF',
408
+ 'NG',
409
+ 'NI',
410
+ 'NL',
411
+ 'NO',
412
+ 'NP',
413
+ 'NR',
414
+ 'NU',
415
+ 'NZ',
416
+ 'OM',
417
+ 'PA',
418
+ 'PE',
419
+ 'PF',
420
+ 'PG',
421
+ 'PH',
422
+ 'PK',
423
+ 'PL',
424
+ 'PM',
425
+ 'PN',
426
+ 'PR',
427
+ 'PS',
428
+ 'PT',
429
+ 'PW',
430
+ 'PY',
431
+ 'QA',
432
+ 'RE',
433
+ 'RO',
434
+ 'RS',
435
+ 'RU',
436
+ 'RW',
437
+ 'SA',
438
+ 'SB',
439
+ 'SC',
440
+ 'SD',
441
+ 'SE',
442
+ 'SG',
443
+ 'SH',
444
+ 'SI',
445
+ 'SK',
446
+ 'SL',
447
+ 'SM',
448
+ 'SN',
449
+ 'SO',
450
+ 'SR',
451
+ 'ST',
452
+ 'SV',
453
+ 'SY',
454
+ 'SZ',
455
+ 'TC',
456
+ 'TD',
457
+ 'TF',
458
+ 'TG',
459
+ 'TH',
460
+ 'TJ',
461
+ 'TK',
462
+ 'TM',
463
+ 'TN',
464
+ 'TO',
465
+ 'TP',
466
+ 'TR',
467
+ 'TT',
468
+ 'TV',
469
+ 'TW',
470
+ 'TZ',
471
+ 'UA',
472
+ 'UG',
473
+ 'US',
474
+ 'UY',
475
+ 'UZ',
476
+ 'VA',
477
+ 'VC',
478
+ 'VE',
479
+ 'VG',
480
+ 'VI',
481
+ 'VN',
482
+ 'VU',
483
+ 'WF',
484
+ 'WS',
485
+ 'XA',
486
+ 'XB',
487
+ 'XC',
488
+ 'XD',
489
+ 'XE',
490
+ 'XF',
491
+ 'XG',
492
+ 'YE',
493
+ 'YT',
494
+ 'ZA',
495
+ 'ZM',
496
+ 'ZW',
497
+ ) );
498
+ }
499
+
500
+ /**
501
+ * Get destination country.
502
+ *
503
+ * @return string
504
+ */
505
+ public function get_destination_country() {
506
+ return $this->destination_country;
507
+ }
508
+
509
+ /**
510
+ * Get origin location.
511
+ *
512
+ * @return string
513
+ */
514
+ public function get_origin_location() {
515
+ $location = 'C' === $this->origin_location ? 'C' : 'I';
516
+
517
+ return apply_filters( 'woocommerce_correios_international_origin_location', $this->origin_location, $this->id, $this->instance_id );
518
+ }
519
+
520
+ /**
521
+ * Get origin state.
522
+ *
523
+ * @return string
524
+ */
525
+ public function get_origin_state() {
526
+ return apply_filters( 'woocommerce_correios_international_origin_state', $this->origin_state, $this->id, $this->instance_id );
527
+ }
528
+
529
+ /**
530
+ * Get height.
531
+ *
532
+ * @return float
533
+ */
534
+ public function get_height() {
535
+ return $this->float_to_string( $this->height );
536
+ }
537
+
538
+ /**
539
+ * Get width.
540
+ *
541
+ * @return float
542
+ */
543
+ public function get_width() {
544
+ return $this->float_to_string( $this->width );
545
+ }
546
+
547
+ /**
548
+ * Get length.
549
+ *
550
+ * @return float
551
+ */
552
+ public function get_length() {
553
+ return $this->float_to_string( $this->length );
554
+ }
555
+
556
+ /**
557
+ * Get weight.
558
+ *
559
+ * @return float
560
+ */
561
+ public function get_weight() {
562
+ return $this->float_to_string( $this->weight );
563
+ }
564
+
565
+ /**
566
+ * Fix number format for XML.
567
+ *
568
+ * @param float $value Value with dot.
569
+ *
570
+ * @return string Value with comma.
571
+ */
572
+ protected function float_to_string( $value ) {
573
+ $value = str_replace( '.', ',', $value );
574
+
575
+ return $value;
576
+ }
577
+
578
+ /**
579
+ * Check if is setted.
580
+ *
581
+ * @return bool
582
+ */
583
+ protected function is_setted() {
584
+ $state = $this->get_origin_state();
585
+
586
+ return ! empty( $this->service ) || ! empty( $this->destination_country ) || ! in_array( $this->destination_country, $this->get_allowed_countries() ) || ! empty( $state ) || 0 === $this->get_height();
587
+ }
588
+
589
+ /**
590
+ * Get shipping prices.
591
+ *
592
+ * @return SimpleXMLElement
593
+ */
594
+ public function get_shipping() {
595
+ $shipping = null;
596
+
597
+ // Checks if services and postcode is empty.
598
+ if ( ! $this->is_setted() ) {
599
+ return $values;
600
+ }
601
+
602
+ $args = apply_filters( 'woocommerce_correios_international_shipping_args', array(
603
+ 'tipoConsulta' => 'Geral',
604
+ 'especif' => $this->service,
605
+ 'uforigem' => $this->get_origin_state(),
606
+ 'localidade' => $this->get_origin_location(),
607
+ 'pais' => $this->get_destination_country(),
608
+ 'altura' => $this->get_height(),
609
+ 'largura' => $this->get_width(),
610
+ 'profundidade' => $this->get_length(),
611
+ 'peso' => $this->get_weight(),
612
+ 'reset' => 'true',
613
+ ), $this->id );
614
+
615
+ $url = add_query_arg( $args, $this->get_webservice_url() );
616
+
617
+ if ( 'yes' == $this->debug ) {
618
+ $this->log->add( $this->id, 'Requesting Correios WebServices: ' . $url );
619
+ }
620
+
621
+ // Gets the WebServices response.
622
+ $response = wp_safe_remote_get( $url, array( 'timeout' => 30 ) );
623
+
624
+ if ( is_wp_error( $response ) ) {
625
+ if ( 'yes' == $this->debug ) {
626
+ $this->log->add( $this->id, 'WP_Error: ' . $response->get_error_message() );
627
+ }
628
+ } elseif ( $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) {
629
+ try {
630
+ $result = wc_correios_safe_load_xml( $response['body'], LIBXML_NOCDATA );
631
+ } catch ( Exception $e ) {
632
+ if ( 'yes' == $this->debug ) {
633
+ $this->log->add( $this->id, 'Correios WebServices invalid XML: ' . $e->getMessage() );
634
+ }
635
+ }
636
+
637
+ if ( isset( $result->tipo_servico ) ) {
638
+ if ( 'yes' == $this->debug ) {
639
+ $this->log->add( $this->id, 'Correios WebServices response: ' . print_r( $result, true ) );
640
+ }
641
+
642
+ $shipping = $result->tipo_servico;
643
+ }
644
+ } else {
645
+ if ( 'yes' == $this->debug ) {
646
+ $this->log->add( $this->id, 'Error accessing the Correios WebServices: ' . print_r( $response, true ) );
647
+ }
648
+ }
649
+
650
+ return $shipping;
651
+ }
652
+ }
includes/class-wc-correios-webservice.php ADDED
@@ -0,0 +1,558 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Correios Webservice.
4
+ *
5
+ * @package WooCommerce_Correios/Classes/Webservice
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * Correios Webservice integration class.
16
+ */
17
+ class WC_Correios_Webservice {
18
+
19
+ /**
20
+ * Webservice URL.
21
+ *
22
+ * @var string
23
+ */
24
+ private $_webservice = 'http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?';
25
+
26
+ /**
27
+ * Shipping method ID.
28
+ *
29
+ * @var string
30
+ */
31
+ protected $id = '';
32
+
33
+ /**
34
+ * Shipping zone instance ID.
35
+ *
36
+ * @var int
37
+ */
38
+ protected $instance_id = 0;
39
+
40
+ /**
41
+ * ID from Correios service.
42
+ *
43
+ * @var string|array
44
+ */
45
+ protected $service = '';
46
+
47
+ /**
48
+ * Origin postcode.
49
+ *
50
+ * @var string
51
+ */
52
+ protected $origin_postcode = '';
53
+
54
+ /**
55
+ * Destination postcode.
56
+ *
57
+ * @var string
58
+ */
59
+ protected $destination_postcode = '';
60
+
61
+ /**
62
+ * Login.
63
+ *
64
+ * @var string
65
+ */
66
+ protected $login = '';
67
+
68
+ /**
69
+ * Password.
70
+ *
71
+ * @var string
72
+ */
73
+ protected $password = '';
74
+
75
+ /**
76
+ * Package height.
77
+ *
78
+ * @var float
79
+ */
80
+ protected $height = 0;
81
+
82
+ /**
83
+ * Package width.
84
+ *
85
+ * @var float
86
+ */
87
+ protected $width = 0;
88
+
89
+ /**
90
+ * Package diameter.
91
+ *
92
+ * @var float
93
+ */
94
+ protected $diameter = 0;
95
+
96
+ /**
97
+ * Package length.
98
+ *
99
+ * @var float
100
+ */
101
+ protected $length = 0;
102
+
103
+ /**
104
+ * Package weight.
105
+ *
106
+ * @var float
107
+ */
108
+ protected $weight = 0;
109
+
110
+ /**
111
+ * Minimum height.
112
+ *
113
+ * @var float
114
+ */
115
+ protected $minimum_height = 2;
116
+
117
+ /**
118
+ * Minimum width.
119
+ *
120
+ * @var float
121
+ */
122
+ protected $minimum_width = 11;
123
+
124
+ /**
125
+ * Minimum length.
126
+ *
127
+ * @var float
128
+ */
129
+ protected $minimum_length = 16;
130
+
131
+ /**
132
+ * Declared value.
133
+ *
134
+ * @var string
135
+ */
136
+ protected $declared_value = '0';
137
+
138
+ /**
139
+ * Own hands.
140
+ *
141
+ * @var string
142
+ */
143
+ protected $own_hands = 'N';
144
+
145
+ /**
146
+ * Receipt notice.
147
+ *
148
+ * @var string
149
+ */
150
+ protected $receipt_notice = 'N';
151
+
152
+ /**
153
+ * Package format.
154
+ *
155
+ * 1 – box/package
156
+ * 2 – roll/prism
157
+ * 3 - envelope
158
+ *
159
+ * @var string
160
+ */
161
+ protected $format = '1';
162
+
163
+ /**
164
+ * Debug mode.
165
+ *
166
+ * @var string
167
+ */
168
+ protected $debug = 'no';
169
+
170
+ /**
171
+ * Logger.
172
+ *
173
+ * @var WC_Logger
174
+ */
175
+ protected $log = null;
176
+
177
+ /**
178
+ * Initialize webservice.
179
+ *
180
+ * @param string $id
181
+ * @param int $instance_id
182
+ */
183
+ public function __construct( $id = 'correios', $instance_id = 0 ) {
184
+ $this->id = $id;
185
+ $this->instance_id = $instance_id;
186
+ $this->log = new WC_Logger();
187
+ }
188
+
189
+ /**
190
+ * Set the service
191
+ *
192
+ * @param string|array $service
193
+ */
194
+ public function set_service( $service = '' ) {
195
+ if ( is_array( $service ) ) {
196
+ $this->service = implode( ',', $service );
197
+ } else {
198
+ $this->service = $service;
199
+ }
200
+ }
201
+
202
+ /**
203
+ * Set shipping package.
204
+ *
205
+ * @param array $package
206
+ */
207
+ public function set_package( $package = array() ) {
208
+ $package = new WC_Correios_Package( $package );
209
+
210
+ if ( ! is_null( $package ) ) {
211
+ $data = $package->get_data();
212
+
213
+ $this->set_height( $data['height'] );
214
+ $this->set_width( $data['width'] );
215
+ $this->set_length( $data['length'] );
216
+ $this->set_weight( $data['weight'] );
217
+ }
218
+
219
+ if ( 'yes' == $this->debug ) {
220
+ if ( ! empty( $data ) ) {
221
+ $data = array(
222
+ 'weight' => $this->get_weight(),
223
+ 'height' => $this->get_height(),
224
+ 'width' => $this->get_width(),
225
+ 'length' => $this->get_length(),
226
+ );
227
+ }
228
+
229
+ $this->log->add( $this->id, 'Weight and cubage of the order: ' . print_r( $data, true ) );
230
+ }
231
+ }
232
+
233
+ /**
234
+ * Set origin postcode.
235
+ *
236
+ * @param string $postcode
237
+ */
238
+ public function set_origin_postcode( $postcode = '' ) {
239
+ $this->origin_postcode = $postcode;
240
+ }
241
+
242
+ /**
243
+ * Set destination postcode.
244
+ *
245
+ * @param string $postcode
246
+ */
247
+ public function set_destination_postcode( $postcode = '' ) {
248
+ $this->destination_postcode = $postcode;
249
+ }
250
+
251
+ /**
252
+ * Set login.
253
+ *
254
+ * @param string $login
255
+ */
256
+ public function set_login( $login = '' ) {
257
+ $this->login = $login;
258
+ }
259
+
260
+ /**
261
+ * Set password.
262
+ *
263
+ * @param string $password
264
+ */
265
+ public function set_password( $password = '' ) {
266
+ $this->password = $password;
267
+ }
268
+
269
+ /**
270
+ * Set shipping package height.
271
+ *
272
+ * @param float $height
273
+ */
274
+ public function set_height( $height = 0 ) {
275
+ $this->height = (float) $height;
276
+ }
277
+
278
+ /**
279
+ * Set shipping package width.
280
+ *
281
+ * @param float $width
282
+ */
283
+ public function set_width( $width = 0 ) {
284
+ $this->width = (float) $width;
285
+ }
286
+
287
+ /**
288
+ * Set shipping package diameter.
289
+ *
290
+ * @param float $diameter
291
+ */
292
+ public function set_diameter( $diameter = 0 ) {
293
+ $this->diameter = (float) $diameter;
294
+ }
295
+
296
+ /**
297
+ * Set shipping package length.
298
+ *
299
+ * @param float $length
300
+ */
301
+ public function set_length( $length = 0 ) {
302
+ $this->length = (float) $length;
303
+ }
304
+
305
+ /**
306
+ * Set shipping package weight.
307
+ *
308
+ * @param float $weight
309
+ */
310
+ public function set_weight( $weight = 0 ) {
311
+ $this->weight = (float) $weight;
312
+ }
313
+
314
+ /**
315
+ * Set minimum height.
316
+ *
317
+ * @param float $minimum_height
318
+ */
319
+ public function set_minimum_height( $minimum_height = 2 ) {
320
+ $this->minimum_height = 2 <= $minimum_height ? $minimum_height : 2;
321
+ }
322
+
323
+ /**
324
+ * Set minimum width.
325
+ *
326
+ * @param float $minimum_width
327
+ */
328
+ public function set_minimum_width( $minimum_width = 11 ) {
329
+ $this->minimum_width = 11 <= $minimum_width ? $minimum_width : 11;
330
+ }
331
+
332
+ /**
333
+ * Set minimum length.
334
+ *
335
+ * @param float $minimum_length
336
+ */
337
+ public function set_minimum_length( $minimum_length = 16 ) {
338
+ $this->minimum_length = 16 <= $minimum_length ? $minimum_length : 16;
339
+ }
340
+
341
+ /**
342
+ * Set declared value.
343
+ *
344
+ * @param string $declared_value
345
+ */
346
+ public function set_declared_value( $declared_value = '0' ) {
347
+ $this->declared_value = $declared_value;
348
+ }
349
+
350
+ /**
351
+ * Set own hands.
352
+ *
353
+ * @param string $own_hands
354
+ */
355
+ public function set_own_hands( $own_hands = 'N' ) {
356
+ $this->own_hands = $own_hands;
357
+ }
358
+
359
+ /**
360
+ * Set receipt notice.
361
+ *
362
+ * @param string $receipt_notice
363
+ */
364
+ public function set_receipt_notice( $receipt_notice = 'N' ) {
365
+ $this->receipt_notice = $receipt_notice;
366
+ }
367
+
368
+ /**
369
+ * Set shipping package format.
370
+ *
371
+ * @param string $format Package format.
372
+ */
373
+ public function set_format( $format = '1' ) {
374
+ $this->format = $format;
375
+ }
376
+
377
+ /**
378
+ * Set the debug mode.
379
+ *
380
+ * @param string $debug Yes or no.
381
+ */
382
+ public function set_debug( $debug = 'no' ) {
383
+ $this->debug = $debug;
384
+ }
385
+
386
+ /**
387
+ * Get webservice URL.
388
+ *
389
+ * @return string
390
+ */
391
+ public function get_webservice_url() {
392
+ return apply_filters( 'woocommerce_correios_webservice_url', $this->_webservice, $this->id, $this->instance_id );
393
+ }
394
+
395
+ /**
396
+ * Get origin postcode.
397
+ *
398
+ * @return string
399
+ */
400
+ public function get_origin_postcode() {
401
+ return apply_filters( 'woocommerce_correios_origin_postcode', $this->origin_postcode, $this->id, $this->instance_id );
402
+ }
403
+
404
+ /**
405
+ * Get login.
406
+ *
407
+ * @return string
408
+ */
409
+ public function get_login() {
410
+ return apply_filters( 'woocommerce_correios_login', $this->login, $this->id, $this->instance_id );
411
+ }
412
+ /**
413
+ * Get password.
414
+ *
415
+ * @return string
416
+ */
417
+ public function get_password() {
418
+ return apply_filters( 'woocommerce_correios_password', $this->password, $this->id, $this->instance_id );
419
+ }
420
+
421
+ /**
422
+ * Get height.
423
+ *
424
+ * @return float
425
+ */
426
+ public function get_height() {
427
+ return $this->float_to_string( $this->minimum_height <= $this->height ? $this->height : $this->minimum_height );
428
+ }
429
+
430
+ /**
431
+ * Get width.
432
+ *
433
+ * @return float
434
+ */
435
+ public function get_width() {
436
+ return $this->float_to_string( $this->minimum_width <= $this->width ? $this->width : $this->minimum_width );
437
+ }
438
+
439
+ /**
440
+ * Get diameter.
441
+ *
442
+ * @return float
443
+ */
444
+ public function get_diameter() {
445
+ return $this->float_to_string( $this->diameter );
446
+ }
447
+
448
+ /**
449
+ * Get length.
450
+ *
451
+ * @return float
452
+ */
453
+ public function get_length() {
454
+ return $this->float_to_string( $this->minimum_length <= $this->length ? $this->length : $this->minimum_length );
455
+ }
456
+
457
+ /**
458
+ * Get weight.
459
+ *
460
+ * @return float
461
+ */
462
+ public function get_weight() {
463
+ return $this->float_to_string( $this->weight );
464
+ }
465
+
466
+ /**
467
+ * Fix number format for XML.
468
+ *
469
+ * @param float $value Value with dot.
470
+ *
471
+ * @return string Value with comma.
472
+ */
473
+ protected function float_to_string( $value ) {
474
+ $value = str_replace( '.', ',', $value );
475
+
476
+ return $value;
477
+ }
478
+
479
+ /**
480
+ * Check if is available.
481
+ *
482
+ * @return bool
483
+ */
484
+ protected function is_available() {
485
+ $origin_postcode = $this->get_origin_postcode();
486
+
487
+ return ! empty( $this->service ) || ! empty( $this->destination_postcode ) || ! empty( $origin_postcode ) || 0 === $this->get_height();
488
+ }
489
+
490
+ /**
491
+ * Get shipping prices.
492
+ *
493
+ * @return SimpleXMLElement|array
494
+ */
495
+ public function get_shipping() {
496
+ $shipping = null;
497
+
498
+ // Checks if service and postcode are empty.
499
+ if ( ! $this->is_available() ) {
500
+ return $shipping;
501
+ }
502
+
503
+ $args = apply_filters( 'woocommerce_correios_shipping_args', array(
504
+ 'nCdServico' => $this->service,
505
+ 'nCdEmpresa' => $this->get_login(),
506
+ 'sDsSenha' => $this->get_password(),
507
+ 'sCepDestino' => wc_correios_sanitize_postcode( $this->destination_postcode ),
508
+ 'sCepOrigem' => wc_correios_sanitize_postcode( $this->get_origin_postcode() ),
509
+ 'nVlAltura' => $this->get_height(),
510
+ 'nVlLargura' => $this->get_width(),
511
+ 'nVlDiametro' => $this->get_diameter(),
512
+ 'nVlComprimento' => $this->get_length(),
513
+ 'nVlPeso' => $this->get_weight(),
514
+ 'nCdFormato' => $this->format,
515
+ 'sCdMaoPropria' => $this->own_hands,
516
+ 'nVlValorDeclarado' => round( number_format( $this->declared_value, 2, '.', '' ) ),
517
+ 'sCdAvisoRecebimento' => $this->receipt_notice,
518
+ 'StrRetorno' => 'xml',
519
+ ), $this->id, $this->instance_id );
520
+
521
+ $url = add_query_arg( $args, $this->get_webservice_url() );
522
+
523
+ if ( 'yes' == $this->debug ) {
524
+ $this->log->add( $this->id, 'Requesting Correios WebServices: ' . $url );
525
+ }
526
+
527
+ // Gets the WebServices response.
528
+ $response = wp_safe_remote_get( esc_url_raw( $url ), array( 'timeout' => 30 ) );
529
+
530
+ if ( is_wp_error( $response ) ) {
531
+ if ( 'yes' == $this->debug ) {
532
+ $this->log->add( $this->id, 'WP_Error: ' . $response->get_error_message() );
533
+ }
534
+ } elseif ( $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) {
535
+ try {
536
+ $result = wc_correios_safe_load_xml( $response['body'], LIBXML_NOCDATA );
537
+ } catch ( Exception $e ) {
538
+ if ( 'yes' == $this->debug ) {
539
+ $this->log->add( $this->id, 'Correios WebServices invalid XML: ' . $e->getMessage() );
540
+ }
541
+ }
542
+
543
+ if ( isset( $result->cServico ) ) {
544
+ if ( 'yes' == $this->debug ) {
545
+ $this->log->add( $this->id, 'Correios WebServices response: ' . print_r( $result, true ) );
546
+ }
547
+
548
+ $shipping = $result->cServico;
549
+ }
550
+ } else {
551
+ if ( 'yes' == $this->debug ) {
552
+ $this->log->add( $this->id, 'Error accessing the Correios WebServices: ' . print_r( $response, true ) );
553
+ }
554
+ }
555
+
556
+ return $shipping;
557
+ }
558
+ }
includes/emails/class-wc-correios-tracking-email.php ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Correios tracking code email.
4
+ *
5
+ * @package WooCommerce_Correios/Classes/Emails
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * Correios Tracking code email.
16
+ */
17
+ class WC_Correios_Tracking_Email extends WC_Email {
18
+
19
+ /**
20
+ * Initialize tracking template.
21
+ */
22
+ public function __construct() {
23
+ $this->id = 'correios_tracking';
24
+ $this->title = __( 'Correios Tracking Code', 'woocommerce-correios' );
25
+ $this->customer_email = true;
26
+ $this->description = __( 'This email is sent when configured a tracking code within an order.', 'woocommerce-correios' );
27
+ $this->heading = __( 'Your order has been sent', 'woocommerce-correios' );
28
+ $this->subject = __( '[{site_title}] Your order {order_number} has been sent by Correios', 'woocommerce-correios' );
29
+ $this->message = __( 'Hi there. Your recent order on {site_title} has been sent by Correios.', 'woocommerce-correios' )
30
+ . PHP_EOL . ' ' . PHP_EOL
31
+ . __( 'To track your delivery, use the following the tracking code: {tracking_code}.', 'woocommerce-correios' )
32
+ . PHP_EOL . ' ' . PHP_EOL
33
+ . __( 'The delivery service is the responsibility of the Correios, but if you have any questions, please contact us.', 'woocommerce-correios' );
34
+ $this->tracking_message = $this->get_option( 'tracking_message', $this->message );
35
+ $this->template_html = 'emails/correios-tracking-code.php';
36
+ $this->template_plain = 'emails/plain/correios-tracking-code.php';
37
+
38
+ // Call parent constructor.
39
+ parent::__construct();
40
+
41
+ $this->template_base = WC_Correios::get_templates_path();
42
+ }
43
+
44
+ /**
45
+ * Initialise settings form fields.
46
+ */
47
+ public function init_form_fields() {
48
+ $this->form_fields = array(
49
+ 'enabled' => array(
50
+ 'title' => __( 'Enable/Disable', 'woocommerce-correios' ),
51
+ 'type' => 'checkbox',
52
+ 'label' => __( 'Enable this email notification', 'woocommerce-correios' ),
53
+ 'default' => 'yes',
54
+ ),
55
+ 'subject' => array(
56
+ 'title' => __( 'Subject', 'woocommerce-correios' ),
57
+ 'type' => 'text',
58
+ 'description' => sprintf( __( 'This controls the email subject line. Leave blank to use the default subject: <code>%s</code>.', 'woocommerce-correios' ), $this->subject ),
59
+ 'placeholder' => $this->subject,
60
+ 'default' => '',
61
+ 'desc_tip' => true,
62
+ ),
63
+ 'heading' => array(
64
+ 'title' => __( 'Email Heading', 'woocommerce-correios' ),
65
+ 'type' => 'text',
66
+ 'description' => sprintf( __( 'This controls the main heading contained within the email. Leave blank to use the default heading: <code>%s</code>.', 'woocommerce-correios' ), $this->heading ),
67
+ 'placeholder' => $this->heading,
68
+ 'default' => '',
69
+ 'desc_tip' => true,
70
+ ),
71
+ 'tracking_message' => array(
72
+ 'title' => __( 'Email Content', 'woocommerce-correios' ),
73
+ 'type' => 'textarea',
74
+ 'description' => sprintf( __( 'This controls the initial content of the email. Leave blank to use the default content: <code>%s</code>.', 'woocommerce-correios' ), $this->message ),
75
+ 'placeholder' => $this->message,
76
+ 'default' => '',
77
+ 'desc_tip' => true,
78
+ ),
79
+ 'email_type' => array(
80
+ 'title' => __( 'Email type', 'woocommerce-correios' ),
81
+ 'type' => 'select',
82
+ 'description' => __( 'Choose which format of email to send.', 'woocommerce-correios' ),
83
+ 'default' => 'html',
84
+ 'class' => 'email_type wc-enhanced-select',
85
+ 'options' => $this->get_custom_email_type_options(),
86
+ 'desc_tip' => true,
87
+ ),
88
+ );
89
+ }
90
+
91
+ /**
92
+ * Email type options.
93
+ *
94
+ * @return array
95
+ */
96
+ protected function get_custom_email_type_options() {
97
+ if ( method_exists( $this, 'get_email_type_options' ) ) {
98
+ return $this->get_email_type_options();
99
+ }
100
+
101
+ $types = array( 'plain' => __( 'Plain text', 'woocommerce-correios' ) );
102
+
103
+ if ( class_exists( 'DOMDocument' ) ) {
104
+ $types['html'] = __( 'HTML', 'woocommerce-correios' );
105
+ $types['multipart'] = __( 'Multipart', 'woocommerce-correios' );
106
+ }
107
+
108
+ return $types;
109
+ }
110
+
111
+ /**
112
+ * Get email tracking message.
113
+ *
114
+ * @return string
115
+ */
116
+ public function get_tracking_message() {
117
+ return apply_filters( 'woocommerce_correios_email_tracking_message', $this->format_string( $this->tracking_message ), $this->object );
118
+ }
119
+
120
+ /**
121
+ * Get tracking code url.
122
+ *
123
+ * @param string $tracking_code Tracking code.
124
+ *
125
+ * @return string
126
+ */
127
+ public function get_tracking_code_url( $tracking_code ) {
128
+ $url = sprintf( '<a href="http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_TIPO=001&P_COD_UNI=%1$s" target="_blank">%1$s</a>', $tracking_code );
129
+
130
+ if ( apply_filters( 'woocommerce_correios_enable_tracking_history', false ) ) {
131
+ $url = sprintf( '<a href="%s#wc-correios-tracking">%s</a>', $this->object->get_view_order_url(), $tracking_code );
132
+ }
133
+
134
+ return apply_filters( 'woocommerce_correios_email_tracking_core_url', $url, $tracking_code, $this->object );
135
+ }
136
+
137
+ /**
138
+ * Trigger email.
139
+ *
140
+ * @param WC_Order $order Order data.
141
+ * @param string $tracking_code Tracking code.
142
+ */
143
+ public function trigger( $order, $tracking_code ) {
144
+ if ( is_object( $order ) ) {
145
+ $this->object = $order;
146
+ $this->recipient = $this->object->billing_email;
147
+
148
+ $this->find[] = '{order_number}';
149
+ $this->replace[] = $this->object->get_order_number();
150
+
151
+ $this->find[] = '{date}';
152
+ $this->replace[] = date_i18n( wc_date_format(), time() );
153
+
154
+ $this->find[] = '{tracking_code}';
155
+ $this->replace[] = $this->get_tracking_code_url( $tracking_code );
156
+ }
157
+
158
+ if ( ! $this->get_recipient() ) {
159
+ return;
160
+ }
161
+
162
+ $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
163
+ }
164
+
165
+ /**
166
+ * Get content HTML.
167
+ *
168
+ * @return string
169
+ */
170
+ public function get_content_html() {
171
+ ob_start();
172
+
173
+ wc_get_template( $this->template_html, array(
174
+ 'order' => $this->object,
175
+ 'email_heading' => $this->get_heading(),
176
+ 'tracking_message' => $this->get_tracking_message(),
177
+ 'sent_to_admin' => false,
178
+ 'plain_text' => false,
179
+ ), '', $this->template_base );
180
+
181
+ return ob_get_clean();
182
+ }
183
+
184
+ /**
185
+ * Get content plain text.
186
+ *
187
+ * @return string
188
+ */
189
+ public function get_content_plain() {
190
+ ob_start();
191
+
192
+ wc_get_template( $this->template_plain, array(
193
+ 'order' => $this->object,
194
+ 'email_heading' => $this->get_heading(),
195
+ 'tracking_message' => $this->get_tracking_message(),
196
+ 'sent_to_admin' => false,
197
+ 'plain_text' => true,
198
+ ), '', $this->template_base );
199
+
200
+ return ob_get_clean();
201
+ }
202
+ }
203
+
204
+ return new WC_Correios_Tracking_Email();
includes/integrations/class-wc-correios-integration.php ADDED
@@ -0,0 +1,290 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Correios integration.
4
+ *
5
+ * @package WooCommerce_Correios/Classes/Integration
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * Correios integration class.
16
+ */
17
+ class WC_Correios_Integration extends WC_Integration {
18
+
19
+ /**
20
+ * Initialize integration actions.
21
+ */
22
+ public function __construct() {
23
+ $this->id = 'correios-integration';
24
+ $this->method_title = __( 'Correios', 'woocommerce-correios' );
25
+
26
+ // Load the form fields.
27
+ $this->init_form_fields();
28
+
29
+ // Load the settings.
30
+ $this->init_settings();
31
+
32
+ // Define user set variables.
33
+ $this->tracking_enable = $this->get_option( 'tracking_enable' );
34
+ $this->tracking_debug = $this->get_option( 'tracking_debug' );
35
+ $this->autofill_enable = $this->get_option( 'autofill_enable' );
36
+ $this->autofill_validity = $this->get_option( 'autofill_validity' );
37
+ $this->autofill_force = $this->get_option( 'autofill_force' );
38
+ $this->autofill_empty_database = $this->get_option( 'autofill_empty_database' );
39
+ $this->autofill_debug = $this->get_option( 'autofill_debug' );
40
+
41
+ // Actions.
42
+ add_action( 'woocommerce_update_options_integration_' . $this->id, array( $this, 'process_admin_options' ) );
43
+
44
+ // Tracking history actions.
45
+ add_filter( 'woocommerce_correios_enable_tracking_history', array( $this, 'setup_tracking_history' ), 10 );
46
+ add_filter( 'woocommerce_correios_enable_tracking_debug', array( $this, 'setup_tracking_debug' ), 10 );
47
+
48
+ // Autofill address actions.
49
+ add_filter( 'woocommerce_correios_enable_autofill_addresses', array( $this, 'setup_autofill_addresses' ), 10 );
50
+ add_filter( 'woocommerce_correios_enable_autofill_addresses_debug', array( $this, 'setup_autofill_addresses_debug' ), 10 );
51
+ add_filter( 'woocommerce_correios_autofill_addresses_validity_time', array( $this, 'setup_autofill_addresses_validity_time' ), 10 );
52
+ add_filter( 'woocommerce_correios_autofill_addresses_force_autofill', array( $this, 'setup_autofill_addresses_force_autofill' ), 10 );
53
+ add_action( 'wp_ajax_correios_autofill_addresses_empty_database', array( $this, 'ajax_empty_database' ) );
54
+ }
55
+
56
+ /**
57
+ * Get tracking log url.
58
+ *
59
+ * @return string
60
+ */
61
+ protected function get_tracking_log_link() {
62
+ if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.2', '>=' ) ) {
63
+ return ' <a href="' . esc_url( admin_url( 'admin.php?page=wc-status&tab=logs&log_file=correios-tracking-history-' . sanitize_file_name( wp_hash( 'correios-tracking-history' ) ) . '.log' ) ) . '">' . __( 'View logs.', 'woocommerce-correios' ) . '</a>';
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Initialize integration settings fields.
69
+ */
70
+ public function init_form_fields() {
71
+ $this->form_fields = array(
72
+ 'tracking' => array(
73
+ 'title' => __( 'Tracking History Table', 'woocommerce-correios' ),
74
+ 'type' => 'title',
75
+ 'description' => __( 'Displays a table with informations about the shipping in My Account > View Order page.', 'woocommerce-correios' ),
76
+ ),
77
+ 'tracking_enable' => array(
78
+ 'title' => __( 'Enable/Disable', 'woocommerce-correios' ),
79
+ 'type' => 'checkbox',
80
+ 'label' => __( 'Enable Tracking History Table', 'woocommerce-correios' ),
81
+ 'default' => 'no',
82
+ ),
83
+ 'tracking_debug' => array(
84
+ 'title' => __( 'Debug Log', 'woocommerce-correios' ),
85
+ 'type' => 'checkbox',
86
+ 'label' => __( 'Enable logging for Tracking History', 'woocommerce-correios' ),
87
+ 'default' => 'no',
88
+ 'description' => sprintf( __( 'Log %s events, such as WebServices requests.', 'woocommerce-correios' ), __( 'Tracking History Table', 'woocommerce-correios' ) ) . $this->get_tracking_log_link(),
89
+ ),
90
+ 'autofill_addresses' => array(
91
+ 'title' => __( 'Autofill Addresses', 'woocommerce-correios' ),
92
+ 'type' => 'title',
93
+ 'description' => __( 'Displays a table with informations about the shipping in My Account > View Order page.', 'woocommerce-correios' ),
94
+ ),
95
+ 'autofill_enable' => array(
96
+ 'title' => __( 'Enable/Disable', 'woocommerce-correios' ),
97
+ 'type' => 'checkbox',
98
+ 'label' => __( 'Enable Autofill Addresses', 'woocommerce-correios' ),
99
+ 'default' => 'no',
100
+ ),
101
+ 'autofill_validity' => array(
102
+ 'title' => __( 'Postcodes Validity', 'woocommerce-correios' ),
103
+ 'type' => 'select',
104
+ 'default' => 'forever',
105
+ 'class' => 'wc-enhanced-select',
106
+ 'description' => __( 'Defines how long a postcode will stay saved in the database before a new query.', 'woocommerce-correios' ),
107
+ 'options' => array(
108
+ '1' => __( '1 month', 'woocommerce-correios' ),
109
+ '2' => sprintf( __( '%d month', 'woocommerce-correios' ), 2 ),
110
+ '3' => sprintf( __( '%d month', 'woocommerce-correios' ), 3 ),
111
+ '4' => sprintf( __( '%d month', 'woocommerce-correios' ), 4 ),
112
+ '5' => sprintf( __( '%d month', 'woocommerce-correios' ), 5 ),
113
+ '6' => sprintf( __( '%d month', 'woocommerce-correios' ), 6 ),
114
+ '7' => sprintf( __( '%d month', 'woocommerce-correios' ), 7 ),
115
+ '8' => sprintf( __( '%d month', 'woocommerce-correios' ), 8 ),
116
+ '9' => sprintf( __( '%d month', 'woocommerce-correios' ), 9 ),
117
+ '10' => sprintf( __( '%d month', 'woocommerce-correios' ), 10 ),
118
+ '11' => sprintf( __( '%d month', 'woocommerce-correios' ), 11 ),
119
+ '12' => sprintf( __( '%d month', 'woocommerce-correios' ), 12 ),
120
+ 'forever' => __( 'Forever', 'woocommerce-correios' ),
121
+ ),
122
+ ),
123
+ 'autofill_force' => array(
124
+ 'title' => __( 'Force Autofill', 'woocommerce-correios' ),
125
+ 'type' => 'checkbox',
126
+ 'label' => __( 'Enable Force Autofill', 'woocommerce-correios' ),
127
+ 'description' => __( 'When enabled will autofill all addresses after the user finish to fill the postcode, even if the addresses are already filled.', 'woocommerce-correios' ),
128
+ 'default' => 'no',
129
+ ),
130
+ 'autofill_empty_database' => array(
131
+ 'title' => __( 'Empty Database', 'woocommerce-correios' ),
132
+ 'type' => 'button',
133
+ 'label' => __( 'Empty Database', 'woocommerce-correios' ),
134
+ 'description' => __( 'Delete all the saved postcodes in the database, use this option if you have issues with outdated postcodes.', 'woocommerce-correios' ),
135
+ ),
136
+ 'autofill_debug' => array(
137
+ 'title' => __( 'Debug Log', 'woocommerce-correios' ),
138
+ 'type' => 'checkbox',
139
+ 'label' => __( 'Enable logging for Autofill Addresses', 'woocommerce-correios' ),
140
+ 'default' => 'no',
141
+ 'description' => sprintf( __( 'Log %s events, such as WebServices requests.', 'woocommerce-correios' ), __( 'Autofill Addresses', 'woocommerce-correios' ) ) . $this->get_tracking_log_link(),
142
+ ),
143
+ );
144
+ }
145
+
146
+ /**
147
+ * Correios options page.
148
+ */
149
+ public function admin_options() {
150
+ echo '<h2>' . esc_html( $this->get_method_title() ) . '</h2>';
151
+ echo wp_kses_post( wpautop( $this->get_method_description() ) );
152
+
153
+ include WC_Correios::get_plugin_path() . 'includes/admin/views/html-admin-help-message.php';
154
+
155
+ if ( class_exists( 'SoapClient' ) ) {
156
+ echo '<div><input type="hidden" name="section" value="' . esc_attr( $this->id ) . '" /></div>';
157
+ echo '<table class="form-table">' . $this->generate_settings_html( $this->get_form_fields(), false ) . '</table>';
158
+ } else {
159
+ $GLOBALS['hide_save_button'] = true; // Hide save button.
160
+ echo '<div class="notice notice-error inline"><p>' . sprintf( __( 'It\'s required have installed the %s on your server in order to integrate with the services of the Correios!', 'woocommerce-correios' ), '<a href="https://secure.php.net/manual/book.soap.php" target="_blank">' . __( 'SOAP module', 'woocommerce-correios' ) . '</a>' ) . '</p></div>';
161
+ }
162
+
163
+ $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
164
+ wp_enqueue_script( $this->id . '-admin', plugins_url( 'assets/js/admin/integration' . $suffix . '.js', WC_Correios::get_main_file() ), array( 'jquery', 'jquery-blockui' ), WC_Correios::VERSION, true );
165
+ wp_localize_script(
166
+ $this->id . '-admin',
167
+ 'WCCorreiosIntegrationAdminParams',
168
+ array(
169
+ 'i18n_confirm_message' => __( 'Are you sure you want to delete all postcodes from the database?', 'woocommerce-correios' ),
170
+ 'empty_database_nonce' => wp_create_nonce( 'woocommerce_correios_autofill_addresses_nonce' ),
171
+ )
172
+ );
173
+ }
174
+
175
+ /**
176
+ * Generate Button Input HTML.
177
+ *
178
+ * @param string $key
179
+ * @param array $data
180
+ * @return string
181
+ */
182
+ public function generate_button_html( $key, $data ) {
183
+ $field_key = $this->get_field_key( $key );
184
+ $defaults = array(
185
+ 'title' => '',
186
+ 'label' => '',
187
+ 'desc_tip' => false,
188
+ 'description' => '',
189
+ );
190
+
191
+ $data = wp_parse_args( $data, $defaults );
192
+
193
+ ob_start();
194
+ ?>
195
+ <tr valign="top">
196
+ <th scope="row" class="titledesc">
197
+ <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
198
+ <?php echo $this->get_tooltip_html( $data ); ?>
199
+ </th>
200
+ <td class="forminp">
201
+ <fieldset>
202
+ <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
203
+ <button class="button-secondary" type="button" id="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['label'] ); ?></button>
204
+ <?php echo $this->get_description_html( $data ); ?>
205
+ </fieldset>
206
+ </td>
207
+ </tr>
208
+ <?php
209
+
210
+ return ob_get_clean();
211
+ }
212
+
213
+ /**
214
+ * Enable tracking history.
215
+ *
216
+ * @return bool
217
+ */
218
+ public function setup_tracking_history() {
219
+ return 'yes' === $this->tracking_enable && class_exists( 'SoapClient' );
220
+ }
221
+
222
+ /**
223
+ * Set up tracking debug.
224
+ *
225
+ * @return bool
226
+ */
227
+ public function setup_tracking_debug() {
228
+ return 'yes' === $this->tracking_debug;
229
+ }
230
+
231
+ /**
232
+ * Enable autofill addresses.
233
+ *
234
+ * @return bool
235
+ */
236
+ public function setup_autofill_addresses() {
237
+ return 'yes' === $this->autofill_enable && class_exists( 'SoapClient' );
238
+ }
239
+
240
+ /**
241
+ * Set up autofill addresses debug.
242
+ *
243
+ * @return bool
244
+ */
245
+ public function setup_autofill_addresses_debug() {
246
+ return 'yes' === $this->autofill_debug;
247
+ }
248
+
249
+ /**
250
+ * Set up autofill addresses validity time.
251
+ *
252
+ * @return string
253
+ */
254
+ public function setup_autofill_addresses_validity_time() {
255
+ return $this->autofill_validity;
256
+ }
257
+
258
+ /**
259
+ * Set up autofill addresses force autofill.
260
+ *
261
+ * @return string
262
+ */
263
+ public function setup_autofill_addresses_force_autofill() {
264
+ return $this->autofill_force;
265
+ }
266
+
267
+ /**
268
+ * Ajax empty database.
269
+ */
270
+ public function ajax_empty_database() {
271
+ global $wpdb;
272
+
273
+ if ( ! isset( $_POST['nonce'] ) ) {
274
+ wp_send_json_error( array( 'message' => __( 'Missing parameters!', 'woocommerce-correios' ) ) );
275
+ exit;
276
+ }
277
+
278
+ if ( ! wp_verify_nonce( $_POST['nonce'], 'woocommerce_correios_autofill_addresses_nonce' ) ) {
279
+ wp_send_json_error( array( 'message' => __( 'Invalid nonce!', 'woocommerce-correios' ) ) );
280
+ exit;
281
+ }
282
+
283
+ $table_name = $wpdb->prefix . WC_Correios_Autofill_Addresses::$table;
284
+ $wpdb->query( "DROP TABLE IF EXISTS $table_name;" );
285
+
286
+ WC_Correios_Autofill_Addresses::create_database();
287
+
288
+ wp_send_json_success( array( 'message' => __( 'Postcode database emptied successfully!', 'woocommerce-correios' ) ) );
289
+ }
290
+ }
includes/shipping/class-wc-correios-shipping-carta-registrada.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Correios Carta Registrada shipping method.
4
+ *
5
+ * @package WooCommerce_Correios/Classes/Shipping
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * Carta Registrada shipping method class.
16
+ */
17
+ class WC_Correios_Shipping_Carta_Registrada extends WC_Correios_Shipping {
18
+
19
+ /**
20
+ * Service code.
21
+ * 10014 - Carta Registrada.
22
+ *
23
+ * @var string
24
+ */
25
+ protected $code = '10014';
26
+
27
+ /**
28
+ * Initialize Carta Registrada.
29
+ *
30
+ * @param int $instance_id Shipping zone instance.
31
+ */
32
+ public function __construct( $instance_id = 0 ) {
33
+ $this->id = 'correios-carta-registrada';
34
+ $this->method_title = __( 'Carta Registrada', 'woocommerce-correios' );
35
+ $this->more_link = 'http://www.correios.com.br/para-voce/correios-de-a-a-z/carta-comercial';
36
+
37
+ parent::__construct( $instance_id );
38
+ }
39
+ }
includes/shipping/class-wc-correios-shipping-esedex.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Correios e-SEDEX shipping method.
4
+ *
5
+ * @package WooCommerce_Correios/Classes/Shipping
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * E-SEDEX shipping method class.
16
+ */
17
+ class WC_Correios_Shipping_ESEDEX extends WC_Correios_Shipping {
18
+
19
+ /**
20
+ * Service code.
21
+ * 81019 - e-SEDEX.
22
+ *
23
+ * @var string
24
+ */
25
+ protected $code = '81019';
26
+
27
+ /**
28
+ * Initialize e-SEDEX.
29
+ *
30
+ * @param int $instance_id Shipping zone instance.
31
+ */
32
+ public function __construct( $instance_id = 0 ) {
33
+ $this->id = 'correios-esedex';
34
+ $this->method_title = __( 'e-SEDEX', 'woocommerce-correios' );
35
+ $this->more_link = 'http://www.correios.com.br/para-voce/correios-de-a-a-z/e-sedex';
36
+
37
+ parent::__construct( $instance_id );
38
+ }
39
+ }
includes/shipping/class-wc-correios-shipping-legacy.php ADDED
@@ -0,0 +1,453 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit;
5
+ }
6
+
7
+ /**
8
+ * Legacy Correios shipping method class.
9
+ */
10
+ class WC_Correios_Shipping_Legacy extends WC_Shipping_Method {
11
+
12
+ /**
13
+ * Initialize the Correios shipping method.
14
+ */
15
+ public function __construct() {
16
+ $this->id = 'correios';
17
+ $this->method_title = __( 'Correios', 'woocommerce-correios' );
18
+ $this->method_description = __( 'Correios is a brazilian delivery method.', 'woocommerce-correios' );
19
+
20
+ // Load the form fields.
21
+ $this->init_form_fields();
22
+
23
+ // Load the settings.
24
+ $this->init_settings();
25
+
26
+ // Define user set variables.
27
+ $this->enabled = $this->get_option( 'enabled' );
28
+ $this->title = $this->get_option( 'title' );
29
+ $this->declare_value = $this->get_option( 'declare_value' );
30
+ $this->display_date = $this->get_option( 'display_date' );
31
+ $this->additional_time = $this->get_option( 'additional_time' );
32
+ $this->fee = $this->get_option( 'fee' );
33
+ $this->zip_origin = $this->get_option( 'zip_origin' );
34
+ $this->corporate_service = $this->get_option( 'corporate_service' );
35
+ $this->login = $this->get_option( 'login' );
36
+ $this->password = $this->get_option( 'password' );
37
+ $this->service_pac = $this->get_option( 'service_pac' );
38
+ $this->service_sedex = $this->get_option( 'service_sedex' );
39
+ $this->service_sedex_10 = $this->get_option( 'service_sedex_10' );
40
+ $this->service_sedex_hoje = $this->get_option( 'service_sedex_hoje' );
41
+ $this->service_esedex = $this->get_option( 'service_esedex' );
42
+ $this->minimum_height = $this->get_option( 'minimum_height' );
43
+ $this->minimum_width = $this->get_option( 'minimum_width' );
44
+ $this->minimum_length = $this->get_option( 'minimum_length' );
45
+ $this->debug = $this->get_option( 'debug' );
46
+
47
+ // Method variables.
48
+ $this->availability = 'specific';
49
+ $this->countries = array( 'BR' );
50
+
51
+ // Actions.
52
+ add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
53
+
54
+ // Active logs.
55
+ if ( 'yes' == $this->debug ) {
56
+ $this->log = new WC_Logger();
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Get log.
62
+ *
63
+ * @return string
64
+ */
65
+ protected function get_log_view() {
66
+ if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.2', '>=' ) ) {
67
+ return '<a href="' . esc_url( admin_url( 'admin.php?page=wc-status&tab=logs&log_file=' . esc_attr( $this->id ) . '-' . sanitize_file_name( wp_hash( $this->id ) ) . '.log' ) ) . '">' . __( 'System Status &gt; Logs', 'woocommerce-correios' ) . '</a>';
68
+ }
69
+
70
+ return '<code>woocommerce/logs/' . esc_attr( $this->id ) . '-' . sanitize_file_name( wp_hash( $this->id ) ) . '.txt</code>';
71
+ }
72
+
73
+ /**
74
+ * Admin options fields.
75
+ */
76
+ public function init_form_fields() {
77
+ $this->form_fields = array(
78
+ 'enabled' => array(
79
+ 'title' => __( 'Enable/Disable', 'woocommerce-correios' ),
80
+ 'type' => 'checkbox',
81
+ 'label' => __( 'Enable this shipping method', 'woocommerce-correios' ),
82
+ 'default' => 'no',
83
+ ),
84
+ 'title' => array(
85
+ 'title' => __( 'Title', 'woocommerce-correios' ),
86
+ 'type' => 'text',
87
+ 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-correios' ),
88
+ 'desc_tip' => true,
89
+ 'default' => __( 'Correios', 'woocommerce-correios' ),
90
+ ),
91
+ 'zip_origin' => array(
92
+ 'title' => __( 'Origin Zip Code', 'woocommerce-correios' ),
93
+ 'type' => 'text',
94
+ 'description' => __( 'Zip Code from where the requests are sent.', 'woocommerce-correios' ),
95
+ 'desc_tip' => true,
96
+ ),
97
+ 'declare_value' => array(
98
+ 'title' => __( 'Declare value', 'woocommerce-correios' ),
99
+ 'type' => 'select',
100
+ 'default' => 'none',
101
+ 'options' => array(
102
+ 'declare' => __( 'Declare', 'woocommerce-correios' ),
103
+ 'none' => __( 'None', 'woocommerce-correios' ),
104
+ ),
105
+ ),
106
+ 'display_date' => array(
107
+ 'title' => __( 'Estimated delivery', 'woocommerce-correios' ),
108
+ 'type' => 'checkbox',
109
+ 'label' => __( 'Enable', 'woocommerce-correios' ),
110
+ 'description' => __( 'Display date of estimated delivery.', 'woocommerce-correios' ),
111
+ 'desc_tip' => true,
112
+ 'default' => 'no',
113
+ ),
114
+ 'additional_time' => array(
115
+ 'title' => __( 'Additional days', 'woocommerce-correios' ),
116
+ 'type' => 'text',
117
+ 'description' => __( 'Additional days to the estimated delivery.', 'woocommerce-correios' ),
118
+ 'desc_tip' => true,
119
+ 'default' => '0',
120
+ 'placeholder' => '0',
121
+ ),
122
+ 'fee' => array(
123
+ 'title' => __( 'Handling Fee', 'woocommerce-correios' ),
124
+ 'type' => 'text',
125
+ 'description' => __( 'Enter an amount, e.g. 2.50, or a percentage, e.g. 5%. Leave blank to disable.', 'woocommerce-correios' ),
126
+ 'desc_tip' => true,
127
+ 'placeholder' => '0.00',
128
+ ),
129
+ 'services' => array(
130
+ 'title' => __( 'Correios Services', 'woocommerce-correios' ),
131
+ 'type' => 'title',
132
+ ),
133
+ 'corporate_service' => array(
134
+ 'title' => __( 'Corporate Service', 'woocommerce-correios' ),
135
+ 'type' => 'select',
136
+ 'description' => __( 'Choose between conventional or corporate service.', 'woocommerce-correios' ),
137
+ 'desc_tip' => true,
138
+ 'default' => 'conventional',
139
+ 'options' => array(
140
+ 'conventional' => __( 'Conventional', 'woocommerce-correios' ),
141
+ 'corporate' => __( 'Corporate', 'woocommerce-correios' ),
142
+ ),
143
+ ),
144
+ 'login' => array(
145
+ 'title' => __( 'Administrative Code', 'woocommerce-correios' ),
146
+ 'type' => 'text',
147
+ 'description' => __( 'Your Correios login.', 'woocommerce-correios' ),
148
+ 'desc_tip' => true,
149
+ ),
150
+ 'password' => array(
151
+ 'title' => __( 'Administrative Password', 'woocommerce-correios' ),
152
+ 'type' => 'password',
153
+ 'description' => __( 'Your Correios password.', 'woocommerce-correios' ),
154
+ 'desc_tip' => true,
155
+ ),
156
+ 'service_pac' => array(
157
+ 'title' => __( 'PAC', 'woocommerce-correios' ),
158
+ 'type' => 'checkbox',
159
+ 'label' => __( 'Enable', 'woocommerce-correios' ),
160
+ 'description' => __( 'Shipping via PAC.', 'woocommerce-correios' ),
161
+ 'desc_tip' => true,
162
+ 'default' => 'no',
163
+ ),
164
+ 'service_sedex' => array(
165
+ 'title' => __( 'SEDEX', 'woocommerce-correios' ),
166
+ 'type' => 'checkbox',
167
+ 'label' => __( 'Enable', 'woocommerce-correios' ),
168
+ 'description' => __( 'Shipping via SEDEX.', 'woocommerce-correios' ),
169
+ 'desc_tip' => true,
170
+ 'default' => 'no',
171
+ ),
172
+ 'service_sedex_10' => array(
173
+ 'title' => __( 'SEDEX 10', 'woocommerce-correios' ),
174
+ 'type' => 'checkbox',
175
+ 'label' => __( 'Enable', 'woocommerce-correios' ),
176
+ 'description' => __( 'Shipping via SEDEX 10.', 'woocommerce-correios' ),
177
+ 'desc_tip' => true,
178
+ 'default' => 'no',
179
+ ),
180
+ 'service_sedex_hoje' => array(
181
+ 'title' => __( 'SEDEX Hoje', 'woocommerce-correios' ),
182
+ 'type' => 'checkbox',
183
+ 'label' => __( 'Enable', 'woocommerce-correios' ),
184
+ 'description' => __( 'Shipping via SEDEX Hoje.', 'woocommerce-correios' ),
185
+ 'desc_tip' => true,
186
+ 'default' => 'no',
187
+ ),
188
+ 'service_esedex' => array(
189
+ 'title' => __( 'e-SEDEX', 'woocommerce-correios' ),
190
+ 'type' => 'checkbox',
191
+ 'label' => __( 'Enable', 'woocommerce-correios' ),
192
+ 'description' => __( 'Shipping via e-SEDEX.', 'woocommerce-correios' ),
193
+ 'desc_tip' => true,
194
+ 'default' => 'no',
195
+ ),
196
+ 'package_standard' => array(
197
+ 'title' => __( 'Package Standard', 'woocommerce-correios' ),
198
+ 'type' => 'title',
199
+ 'description' => __( 'Sets a minimum measure for the package.', 'woocommerce-correios' ),
200
+ 'desc_tip' => true,
201
+ ),
202
+ 'minimum_height' => array(
203
+ 'title' => __( 'Minimum Height', 'woocommerce-correios' ),
204
+ 'type' => 'text',
205
+ 'description' => __( 'Minimum height of the package. Correios needs at least 2 cm.', 'woocommerce-correios' ),
206
+ 'desc_tip' => true,
207
+ 'default' => '2',
208
+ ),
209
+ 'minimum_width' => array(
210
+ 'title' => __( 'Minimum Width', 'woocommerce-correios' ),
211
+ 'type' => 'text',
212
+ 'description' => __( 'Minimum width of the package. Correios needs at least 11 cm.', 'woocommerce-correios' ),
213
+ 'desc_tip' => true,
214
+ 'default' => '11',
215
+ ),
216
+ 'minimum_length' => array(
217
+ 'title' => __( 'Minimum Length', 'woocommerce-correios' ),
218
+ 'type' => 'text',
219
+ 'description' => __( 'Minimum length of the package. Correios needs at least 16 cm.', 'woocommerce-correios' ),
220
+ 'desc_tip' => true,
221
+ 'default' => '16',
222
+ ),
223
+ 'testing' => array(
224
+ 'title' => __( 'Testing', 'woocommerce-correios' ),
225
+ 'type' => 'title',
226
+ ),
227
+ 'debug' => array(
228
+ 'title' => __( 'Debug Log', 'woocommerce-correios' ),
229
+ 'type' => 'checkbox',
230
+ 'label' => __( 'Enable logging', 'woocommerce-correios' ),
231
+ 'default' => 'no',
232
+ 'description' => sprintf( __( 'Log Correios events, such as WebServices requests, inside %s.', 'woocommerce-correios' ), $this->get_log_view() ),
233
+ ),
234
+ );
235
+ }
236
+
237
+ /**
238
+ * Correios options page.
239
+ */
240
+ public function admin_options() {
241
+ $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
242
+
243
+ // Call the admin scripts.
244
+ wp_enqueue_script( 'wc-correios', plugins_url( 'assets/js/admin/shipping-methods' . $suffix . '.js', WC_Correios::get_main_file() ), array( 'jquery' ), '', true );
245
+
246
+ echo '<h3>' . esc_html( $this->method_title ) . '</h3>';
247
+
248
+ echo '<p>' . esc_html( $this->method_description ) . '</p>';
249
+
250
+ if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.6.0', '>=' ) ) {
251
+ echo '<div class="error inline">';
252
+ echo '<p><strong>' . sprintf( __( 'This shipping method this depreciated since %s, and you should configure shipping methods in the new Shipping Zones screen.', 'woocommerce-correios' ), 'WooCommerce 2.6' ) . ' <a href="https://youtu.be/3z9j0NPU_O0">' . __( 'See how to configure.', 'woocommerce-correios' ) . '</a></strong></p>';
253
+ echo '</div>';
254
+ } else {
255
+ include WC_Correios::get_plugin_path() . 'includes/admin/views/html-admin-help-message.php';
256
+ }
257
+
258
+ echo '<table class="form-table">';
259
+ $this->generate_settings_html();
260
+ echo '</table>';
261
+ }
262
+
263
+ /**
264
+ * Gets the services IDs.
265
+ *
266
+ * @return array
267
+ */
268
+ protected function correios_services() {
269
+ $services = array();
270
+
271
+ $services['PAC'] = ( 'yes' == $this->service_pac ) ? '41106' : '';
272
+ $services['SEDEX'] = ( 'yes' == $this->service_sedex ) ? '40010' : '';
273
+ $services['SEDEX 10'] = ( 'yes' == $this->service_sedex_10 ) ? '40215' : '';
274
+ $services['SEDEX Hoje'] = ( 'yes' == $this->service_sedex_hoje ) ? '40290' : '';
275
+
276
+ if ( 'corporate' == $this->corporate_service ) {
277
+ $services['PAC'] = ( 'yes' == $this->service_pac ) ? '41068' : '';
278
+ $services['SEDEX'] = ( 'yes' == $this->service_sedex ) ? '40096' : '';
279
+ $services['e-SEDEX'] = ( 'yes' == $this->service_esedex ) ? '81019' : '';
280
+ }
281
+
282
+ return array_filter( $services );
283
+ }
284
+
285
+ /**
286
+ * Get cart total.
287
+ *
288
+ * @return float
289
+ */
290
+ protected function get_cart_total() {
291
+ if ( ! WC()->cart->prices_include_tax ) {
292
+ return WC()->cart->cart_contents_total;
293
+ }
294
+
295
+ return WC()->cart->cart_contents_total + WC()->cart->tax_total;
296
+ }
297
+
298
+ /**
299
+ * Gets the price of shipping.
300
+ *
301
+ * @param array $package Order package.
302
+ *
303
+ * @return array Correios Quotes.
304
+ */
305
+ protected function correios_calculate( $package ) {
306
+ $services = array_values( $this->correios_services() );
307
+ $connect = new WC_Correios_Webservice( $this->id );
308
+ $connect->set_debug( $this->debug );
309
+ $connect->set_service( $services );
310
+ $connect->set_package( $package );
311
+ $connect->set_origin_postcode( $this->zip_origin );
312
+ $connect->set_destination_postcode( $package['destination']['postcode'] );
313
+
314
+ if ( 'declare' == $this->declare_value ) {
315
+ $connect->set_declared_value( $this->get_cart_total() );
316
+ }
317
+
318
+ if ( 'corporate' == $this->corporate_service ) {
319
+ $connect->set_login( $this->login );
320
+ $connect->set_password( $this->password );
321
+ }
322
+
323
+ $connect->set_minimum_height( $this->minimum_height );
324
+ $connect->set_minimum_width( $this->minimum_width );
325
+ $connect->set_minimum_length( $this->minimum_length );
326
+
327
+ $shipping = $connect->get_shipping();
328
+
329
+ if ( ! empty( $shipping ) ) {
330
+ return $shipping;
331
+ } else {
332
+ // Cart only with virtual products.
333
+ if ( 'yes' == $this->debug ) {
334
+ $this->log->add( 'correios', 'Cart only with virtual products.' );
335
+ }
336
+
337
+ return array();
338
+ }
339
+ }
340
+
341
+ /**
342
+ * Gets the service name.
343
+ *
344
+ * @param int $code Correios service ID.
345
+ *
346
+ * @return array Correios service name.
347
+ */
348
+ protected function get_service_name( $code ) {
349
+ $name = array(
350
+ '41106' => 'PAC',
351
+ '40010' => 'SEDEX',
352
+ '40215' => 'SEDEX 10',
353
+ '40290' => 'SEDEX Hoje',
354
+ '41068' => 'PAC',
355
+ '40096' => 'SEDEX',
356
+ '81019' => 'e-SEDEX',
357
+ );
358
+
359
+ return isset( $name[ $code ] ) ? $name[ $code ] : '';
360
+ }
361
+
362
+ /**
363
+ * Get additional time.
364
+ *
365
+ * @param array $package Package data.
366
+ *
367
+ * @return array
368
+ */
369
+ protected function get_additional_time( $package = array() ) {
370
+ return apply_filters( 'woocommerce_correios_shipping_additional_time', $this->additional_time, $package );
371
+ }
372
+
373
+ /**
374
+ * Get accepted error codes.
375
+ *
376
+ * @return array
377
+ */
378
+ protected function get_accepted_error_codes() {
379
+ $codes = apply_filters( 'woocommerce_correios_accepted_error_codes', array( '-33', '-3', '010' ) );
380
+ $codes[] = '0';
381
+
382
+ return $codes;
383
+ }
384
+
385
+ /**
386
+ * Calculates the shipping rate.
387
+ *
388
+ * @param array $package Order package.
389
+ */
390
+ public function calculate_shipping( $package = array() ) {
391
+ $rates = array();
392
+ $errors = array();
393
+ $shipping_values = $this->correios_calculate( $package );
394
+
395
+ if ( ! empty( $shipping_values ) ) {
396
+ foreach ( $shipping_values as $shipping ) {
397
+ if ( ! isset( $shipping->Erro ) ) {
398
+ continue;
399
+ }
400
+
401
+ $name = $this->get_service_name( (string) $shipping->Codigo );
402
+ $error_number = (string) $shipping->Erro;
403
+ $error_message = wc_correios_get_error_message( $error_number );
404
+ $errors[ $error_number ] = array(
405
+ 'error' => $error_message,
406
+ 'number' => $error_number,
407
+ );
408
+
409
+ if ( ! in_array( $error_number, $this->get_accepted_error_codes() ) ) {
410
+ continue;
411
+ }
412
+
413
+ // Set the shipping rates.
414
+ $label = ( 'yes' == $this->display_date ) ? wc_correios_get_estimating_delivery( $name, (int) $shipping->PrazoEntrega, $this->get_additional_time( $package ) ) : $name;
415
+ $cost = wc_correios_normalize_price( esc_attr( (string) $shipping->Valor ) );
416
+
417
+ // Exit if don't have price.
418
+ if ( 0 === intval( $cost ) ) {
419
+ return;
420
+ }
421
+
422
+ $fee = $this->get_fee( str_replace( ',', '.', $this->fee ), $cost );
423
+
424
+ array_push(
425
+ $rates,
426
+ array(
427
+ 'id' => $name,
428
+ 'label' => $label,
429
+ 'cost' => $cost + $fee,
430
+ )
431
+ );
432
+ }
433
+
434
+ // Display correios errors.
435
+ if ( ! empty( $errors ) ) {
436
+ foreach ( $errors as $error ) {
437
+ if ( '' != $error['error'] ) {
438
+ $type = ( '010' == $error['number'] ) ? 'notice' : 'error';
439
+ $message = '<strong>' . __( 'Correios', 'woocommerce-correios' ) . ':</strong> ' . esc_attr( $error['error'] );
440
+ wc_add_notice( $message, $type );
441
+ }
442
+ }
443
+ }
444
+
445
+ $rates = apply_filters( 'woocommerce_correios_shipping_methods', $rates, $package );
446
+
447
+ // Add rates.
448
+ foreach ( $rates as $rate ) {
449
+ $this->add_rate( $rate );
450
+ }
451
+ }
452
+ }
453
+ }
includes/shipping/class-wc-correios-shipping-leve-internacional.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Correios Leve Internacional shipping method.
4
+ *
5
+ * @package WooCommerce_Correios/Classes/Shipping
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * Leve Internacional shipping method class.
16
+ */
17
+ class WC_Correios_Shipping_Leve_Internacional extends WC_Correios_International_Shipping {
18
+
19
+ /**
20
+ * Service code.
21
+ * 209 - Leve Internacional.
22
+ *
23
+ * @var string
24
+ */
25
+ protected $code = '209';
26
+
27
+ /**
28
+ * Initialize Leve Internacional.
29
+ *
30
+ * @param int $instance_id Shipping zone instance.
31
+ */
32
+ public function __construct( $instance_id = 0 ) {
33
+ $this->id = 'correios-leve-internacional';
34
+ $this->method_title = __( 'Leve Internacional', 'woocommerce-correios' ) . ' ' . __( '(beta)', 'woocommerce-correios' );
35
+ $this->more_link = '';
36
+
37
+ parent::__construct( $instance_id );
38
+ }
39
+ }
includes/shipping/class-wc-correios-shipping-mercadoria-economica.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Correios Mercadoria Econômica shipping method.
4
+ *
5
+ * @package WooCommerce_Correios/Classes/Shipping
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * Mercadoria Econômica shipping method class.
16
+ */
17
+ class WC_Correios_Shipping_Mercadoria_Economica extends WC_Correios_International_Shipping {
18
+
19
+ /**
20
+ * Service code.
21
+ * 128 - Mercadoria Econômica.
22
+ *
23
+ * @var string
24
+ */
25
+ protected $code = '128';
26
+
27
+ /**
28
+ * Initialize Mercadoria Econômica.
29
+ *
30
+ * @param int $instance_id Shipping zone instance.
31
+ */
32
+ public function __construct( $instance_id = 0 ) {
33
+ $this->id = 'correios-mercadoria-economica';
34
+ $this->method_title = __( 'Mercadoria Econ&ocirc;mica', 'woocommerce-correios' ) . ' ' . __( '(beta)', 'woocommerce-correios' );
35
+ $this->more_link = '';
36
+
37
+ parent::__construct( $instance_id );
38
+ }
39
+ }
includes/shipping/class-wc-correios-shipping-mercadoria-expressa.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Correios Mercadoria Expressa shipping method.
4
+ *
5
+ * @package WooCommerce_Correios/Classes/Shipping
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * Mercadoria Expressa shipping method class.
16
+ */
17
+ class WC_Correios_Shipping_Mercadoria_Expressa extends WC_Correios_International_Shipping {
18
+
19
+ /**
20
+ * Service code.
21
+ * 110 - Mercadoria Expressa.
22
+ *
23
+ * @var string
24
+ */
25
+ protected $code = '110';
26
+
27
+ /**
28
+ * Initialize Mercadoria Expressa.
29
+ *
30
+ * @param int $instance_id Shipping zone instance.
31
+ */
32
+ public function __construct( $instance_id = 0 ) {
33
+ $this->id = 'correios-mercadoria-expressa';
34
+ $this->method_title = __( 'Mercadoria Expressa', 'woocommerce-correios' ) . ' ' . __( '(beta)', 'woocommerce-correios' );
35
+ $this->more_link = '';
36
+
37
+ parent::__construct( $instance_id );
38
+ }
39
+ }
includes/shipping/class-wc-correios-shipping-pac.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Correios PAC shipping method.
4
+ *
5
+ * @package WooCommerce_Correios/Classes/Shipping
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * PAC shipping method class.
16
+ */
17
+ class WC_Correios_Shipping_PAC extends WC_Correios_Shipping {
18
+
19
+ /**
20
+ * Service code.
21
+ * 41106 - PAC without contract.
22
+ *
23
+ * @var string
24
+ */
25
+ protected $code = '41106';
26
+
27
+ /**
28
+ * Corporate code.
29
+ * 41068 - PAC with contract.
30
+ *
31
+ * @var string
32
+ */
33
+ protected $corporate_code = '41068';
34
+
35
+ /**
36
+ * Initialize PAC.
37
+ *
38
+ * @param int $instance_id Shipping zone instance.
39
+ */
40
+ public function __construct( $instance_id = 0 ) {
41
+ $this->id = 'correios-pac';
42
+ $this->method_title = __( 'PAC', 'woocommerce-correios' );
43
+ $this->more_link = 'http://www.correios.com.br/para-voce/correios-de-a-a-z/pac-encomenda-economica';
44
+
45
+ parent::__construct( $instance_id );
46
+ }
47
+ }
includes/shipping/class-wc-correios-shipping-sedex-hoje.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Correios SEDEX Hoje shipping method.
4
+ *
5
+ * @package WooCommerce_Correios/Classes/Shipping
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * SEDEX Hoje shipping method class.
16
+ */
17
+ class WC_Correios_Shipping_SEDEX_Hoje extends WC_Correios_Shipping {
18
+
19
+ /**
20
+ * Service code.
21
+ * 40290 - SEDEX Hoje without contract.
22
+ *
23
+ * @var string
24
+ */
25
+ protected $code = '40290';
26
+
27
+ /**
28
+ * Initialize SEDEX Hoje.
29
+ *
30
+ * @param int $instance_id Shipping zone instance.
31
+ */
32
+ public function __construct( $instance_id = 0 ) {
33
+ $this->id = 'correios-sedex-hoje';
34
+ $this->method_title = __( 'SEDEX Hoje', 'woocommerce-correios' );
35
+ $this->more_link = 'http://www.correios.com.br/para-voce/correios-de-a-a-z/sedex-hoje';
36
+
37
+ parent::__construct( $instance_id );
38
+ }
39
+ }
includes/shipping/class-wc-correios-shipping-sedex.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Correios SEDEX shipping method.
4
+ *
5
+ * @package WooCommerce_Correios/Classes/Shipping
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * SEDEX shipping method class.
16
+ */
17
+ class WC_Correios_Shipping_SEDEX extends WC_Correios_Shipping {
18
+
19
+ /**
20
+ * Service code.
21
+ * 40010 - SEDEX without contract.
22
+ *
23
+ * @var string
24
+ */
25
+ protected $code = '40010';
26
+
27
+ /**
28
+ * Corporate code.
29
+ * 40096 - SEDEX with contract.
30
+ *
31
+ * @var string
32
+ */
33
+ protected $corporate_code = '40096';
34
+
35
+ /**
36
+ * Initialize SEDEX.
37
+ *
38
+ * @param int $instance_id Shipping zone instance.
39
+ */
40
+ public function __construct( $instance_id = 0 ) {
41
+ $this->id = 'correios-sedex';
42
+ $this->method_title = __( 'SEDEX', 'woocommerce-correios' );
43
+ $this->more_link = 'http://www.correios.com.br/para-voce/correios-de-a-a-z/sedex';
44
+
45
+ parent::__construct( $instance_id );
46
+ }
47
+ }
includes/shipping/class-wc-correios-shipping-sedex10-envelope.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Correios SEDEX 10 Envelope shipping method.
4
+ *
5
+ * @package WooCommerce_Correios/Classes/Shipping
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * SEDEX 10 Envelope shipping method class.
16
+ */
17
+ class WC_Correios_Shipping_SEDEX_10_Envelope extends WC_Correios_Shipping {
18
+
19
+ /**
20
+ * Service code.
21
+ * 40215 - SEDEX 10 Envelope.
22
+ *
23
+ * @var string
24
+ */
25
+ protected $code = '40215';
26
+
27
+ /**
28
+ * Initialize SEDEX 10 Envelope.
29
+ *
30
+ * @param int $instance_id Shipping zone instance.
31
+ */
32
+ public function __construct( $instance_id = 0 ) {
33
+ $this->id = 'correios-sedex10-envelope';
34
+ $this->method_title = __( 'SEDEX 10 Envelope', 'woocommerce-correios' );
35
+ $this->more_link = 'http://www.correios.com.br/para-voce/correios-de-a-a-z/sedex-10';
36
+
37
+ parent::__construct( $instance_id );
38
+ }
39
+ }
includes/shipping/class-wc-correios-shipping-sedex10-pacote.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Correios SEDEX 10 Pacote shipping method.
4
+ *
5
+ * @package WooCommerce_Correios/Classes/Shipping
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * SEDEX 10 Pacote shipping method class.
16
+ */
17
+ class WC_Correios_Shipping_SEDEX_10_Pacote extends WC_Correios_Shipping {
18
+
19
+ /**
20
+ * Service code.
21
+ * 40886 - SEDEX 10 Pacote.
22
+ *
23
+ * @var string
24
+ */
25
+ protected $code = '40886';
26
+
27
+ /**
28
+ * Initialize SEDEX 10 Pacote.
29
+ *
30
+ * @param int $instance_id Shipping zone instance.
31
+ */
32
+ public function __construct( $instance_id = 0 ) {
33
+ $this->id = 'correios-sedex10-pacote';
34
+ $this->method_title = __( 'SEDEX 10 Pacote', 'woocommerce-correios' );
35
+ $this->more_link = 'http://www.correios.com.br/para-voce/correios-de-a-a-z/sedex-10';
36
+
37
+ parent::__construct( $instance_id );
38
+ }
39
+ }
includes/shipping/class-wc-correios-shipping-sedex12.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Correios SEDEX 12 shipping method.
4
+ *
5
+ * @package WooCommerce_Correios/Classes/Shipping
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * SEDEX 12 shipping method class.
16
+ */
17
+ class WC_Correios_Shipping_SEDEX_12 extends WC_Correios_Shipping {
18
+
19
+ /**
20
+ * Service code.
21
+ * 40169 - SEDEX 12.
22
+ *
23
+ * @var string
24
+ */
25
+ protected $code = '40169';
26
+
27
+ /**
28
+ * Initialize SEDEX 12.
29
+ *
30
+ * @param int $instance_id Shipping zone instance.
31
+ */
32
+ public function __construct( $instance_id = 0 ) {
33
+ $this->id = 'correios-sedex12';
34
+ $this->method_title = __( 'SEDEX 12', 'woocommerce-correios' );
35
+ $this->more_link = 'http://www.correios.com.br/para-voce/correios-de-a-a-z/sedex-12';
36
+
37
+ parent::__construct( $instance_id );
38
+ }
39
+ }
includes/wc-correios-functions.php ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Correios functions.
4
+ *
5
+ * @package WooCommerce_Correios/Functions
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * Safe load XML.
16
+ *
17
+ * @throws Exception Show detected errors while parsing the data.
18
+ *
19
+ * @param string $source Source XML.
20
+ * @param int $options Reading options.
21
+ *
22
+ * @return SimpleXMLElement|bool
23
+ */
24
+ function wc_correios_safe_load_xml( $source, $options = 0 ) {
25
+ $old = null;
26
+
27
+ if ( function_exists( 'libxml_disable_entity_loader' ) ) {
28
+ $old = libxml_disable_entity_loader( true );
29
+ }
30
+
31
+ $dom = new DOMDocument();
32
+ $return = $dom->loadXML( $source, $options );
33
+
34
+ if ( ! is_null( $old ) ) {
35
+ libxml_disable_entity_loader( $old );
36
+ }
37
+
38
+ if ( ! $return ) {
39
+ return false;
40
+ }
41
+
42
+ if ( isset( $dom->doctype ) ) {
43
+ throw new Exception( 'Unsafe DOCTYPE Detected while XML parsing' );
44
+
45
+ return false;
46
+ }
47
+
48
+ return simplexml_import_dom( $dom );
49
+ }
50
+
51
+ /**
52
+ * Sanitize postcode.
53
+ *
54
+ * @param string $postcode Postcode.
55
+ *
56
+ * @return string
57
+ */
58
+ function wc_correios_sanitize_postcode( $postcode ) {
59
+ return preg_replace( '([^0-9])', '', sanitize_text_field( $postcode ) );
60
+ }
61
+
62
+ /**
63
+ * Get estimating delivery description.
64
+ *
65
+ * @param string $name Shipping name.
66
+ * @param string $days Estimated days to accomplish delivery.
67
+ * @param int $additional_days Additional days.
68
+ *
69
+ * @return string
70
+ */
71
+ function wc_correios_get_estimating_delivery( $name, $days, $additional_days = 0 ) {
72
+ $total = intval( $days ) + intval( $additional_days );
73
+
74
+ if ( $total > 0 ) {
75
+ $name .= ' (' . sprintf( _n( 'Delivery within %d working day', 'Delivery within %d working days', $total, 'woocommerce-correios' ), $total ) . ')';
76
+ }
77
+
78
+ return $name;
79
+ }
80
+
81
+ /**
82
+ * Fix Correios prices.
83
+ *
84
+ * @param string $value Value to fix.
85
+ *
86
+ * @return string
87
+ */
88
+ function wc_correios_normalize_price( $value ) {
89
+ $value = str_replace( '.', '', $value );
90
+ $value = str_replace( ',', '.', $value );
91
+
92
+ return $value;
93
+ }
94
+
95
+ /**
96
+ * Get error messages.
97
+ *
98
+ * @param string $code Error code.
99
+ *
100
+ * @return string
101
+ */
102
+ function wc_correios_get_error_message( $code ) {
103
+ $code = (string) $code;
104
+
105
+ $messages = apply_filters( 'woocommerce_correios_available_error_messages', array(
106
+ '-33' => __( 'System temporarily down. Please try again later.', 'woocommerce-correios' ),
107
+ '-3' => __( 'Invalid zip code.', 'woocommerce-correios' ),
108
+ '010' => __( 'Area with delivery temporarily subjected to different periods.', 'woocommerce-correios' ),
109
+ ) );
110
+
111
+ return isset( $messages[ $code ] ) ? $messages[ $code ] : '';
112
+ }
113
+
114
+ /**
115
+ * Trigger tracking code email notification.
116
+ *
117
+ * @param WC_Order $order Order data.
118
+ * @param string $tracking_code The Correios tracking code.
119
+ */
120
+ function wc_correios_trigger_tracking_code_email( $order, $tracking_code ) {
121
+ $mailer = WC()->mailer();
122
+ $notification = $mailer->emails['WC_Correios_Tracking_Email'];
123
+
124
+ if ( 'yes' === $notification->enabled ) {
125
+ $notification->trigger( $order, $tracking_code );
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Update tracking code.
131
+ *
132
+ * @param int $order_id Order ID.
133
+ * @param string $tracking_code Tracking code.
134
+ * @return bool
135
+ */
136
+ function wc_correios_update_tracking_code( $order_id, $tracking_code ) {
137
+ $tracking_code = sanitize_text_field( $tracking_code );
138
+ $current = get_post_meta( $order_id, '_correios_tracking_code', true );
139
+
140
+ if ( '' !== $tracking_code && $tracking_code !== $current ) {
141
+ update_post_meta( $order_id, '_correios_tracking_code', $tracking_code );
142
+
143
+ // Gets order data.
144
+ $order = wc_get_order( $order_id );
145
+
146
+ // Add order note.
147
+ $order->add_order_note( sprintf( __( 'Added a Correios tracking code: %s', 'woocommerce-correios' ), $tracking_code ) );
148
+
149
+ // Send email notification.
150
+ wc_correios_trigger_tracking_code_email( $order, $tracking_code );
151
+
152
+ return true;
153
+ } elseif ( '' === $tracking_code ) {
154
+ delete_post_meta( $order_id, '_correios_tracking_code' );
155
+
156
+ return true;
157
+ }
158
+
159
+ return false;
160
+ }
languages/woocommerce-correios.pot ADDED
@@ -0,0 +1,830 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2016 Claudio Sanches
2
+ # This file is distributed under the GPLv2 or later.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: WooCommerce Correios 3.0.0\n"
6
+ "Report-Msgid-Bugs-To: https://wordpress.org/plugins/woocommerce-domination/\n"
7
+ "POT-Creation-Date: 2016-06-26 21:19:58+00:00\n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=utf-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n"
12
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
+ "Language-Team: LANGUAGE <EMAIL@ADDRESS>\n"
14
+ "X-Generator: grunt-wp-i18n 0.5.4\n"
15
+
16
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:28
17
+ msgid "%s is a international shipping method from Correios."
18
+ msgstr ""
19
+
20
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:63
21
+ #: includes/abstracts/abstract-wc-correios-shipping.php:106
22
+ #: includes/emails/class-wc-correios-tracking-email.php:50
23
+ #: includes/integrations/class-wc-correios-integration.php:78
24
+ #: includes/integrations/class-wc-correios-integration.php:96
25
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:79
26
+ msgid "Enable/Disable"
27
+ msgstr ""
28
+
29
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:65
30
+ #: includes/abstracts/abstract-wc-correios-shipping.php:108
31
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:81
32
+ msgid "Enable this shipping method"
33
+ msgstr ""
34
+
35
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:69
36
+ #: includes/abstracts/abstract-wc-correios-shipping.php:112
37
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:85
38
+ msgid "Title"
39
+ msgstr ""
40
+
41
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:71
42
+ #: includes/abstracts/abstract-wc-correios-shipping.php:114
43
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:87
44
+ msgid "This controls the title which the user sees during checkout."
45
+ msgstr ""
46
+
47
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:76
48
+ #: includes/abstracts/abstract-wc-correios-shipping.php:119
49
+ msgid "Behavior Options"
50
+ msgstr ""
51
+
52
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:81
53
+ msgid "Origin State"
54
+ msgstr ""
55
+
56
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:83
57
+ msgid "The UF of the location your packages are delivered from."
58
+ msgstr ""
59
+
60
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:90
61
+ msgid "Origin Locale"
62
+ msgstr ""
63
+
64
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:92
65
+ msgid "The location of your packages are delivered from."
66
+ msgstr ""
67
+
68
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:97
69
+ msgid "Capital"
70
+ msgstr ""
71
+
72
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:98
73
+ msgid "Interior"
74
+ msgstr ""
75
+
76
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:102
77
+ #: includes/abstracts/abstract-wc-correios-shipping.php:132
78
+ msgid "Delivery Time"
79
+ msgstr ""
80
+
81
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:104
82
+ #: includes/abstracts/abstract-wc-correios-shipping.php:134
83
+ msgid "Show estimated delivery time"
84
+ msgstr ""
85
+
86
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:105
87
+ #: includes/abstracts/abstract-wc-correios-shipping.php:135
88
+ msgid "Display the estimated delivery time in working days."
89
+ msgstr ""
90
+
91
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:110
92
+ #: includes/abstracts/abstract-wc-correios-shipping.php:148
93
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:123
94
+ msgid "Handling Fee"
95
+ msgstr ""
96
+
97
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:112
98
+ #: includes/abstracts/abstract-wc-correios-shipping.php:150
99
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:125
100
+ msgid ""
101
+ "Enter an amount, e.g. 2.50, or a percentage, e.g. 5%. Leave blank to "
102
+ "disable."
103
+ msgstr ""
104
+
105
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:118
106
+ #: includes/abstracts/abstract-wc-correios-shipping.php:156
107
+ msgid "Optional Services"
108
+ msgstr ""
109
+
110
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:120
111
+ #: includes/abstracts/abstract-wc-correios-shipping.php:158
112
+ msgid "Use these options to add the value of each service provided by the Correios."
113
+ msgstr ""
114
+
115
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:124
116
+ msgid "Automatic Insurance"
117
+ msgstr ""
118
+
119
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:126
120
+ msgid "Enable automatic insurance"
121
+ msgstr ""
122
+
123
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:127
124
+ msgid "This controls if need to apply insurance to the order."
125
+ msgstr ""
126
+
127
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:132
128
+ #: includes/abstracts/abstract-wc-correios-shipping.php:252
129
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:224
130
+ msgid "Testing"
131
+ msgstr ""
132
+
133
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:137
134
+ #: includes/abstracts/abstract-wc-correios-shipping.php:257
135
+ #: includes/integrations/class-wc-correios-integration.php:84
136
+ #: includes/integrations/class-wc-correios-integration.php:137
137
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:228
138
+ msgid "Debug Log"
139
+ msgstr ""
140
+
141
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:139
142
+ #: includes/abstracts/abstract-wc-correios-shipping.php:259
143
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:230
144
+ msgid "Enable logging"
145
+ msgstr ""
146
+
147
+ #: includes/abstracts/abstract-wc-correios-international-shipping.php:141
148
+ #: includes/abstracts/abstract-wc-correios-shipping.php:261
149
+ #: includes/integrations/class-wc-correios-integration.php:88
150
+ #: includes/integrations/class-wc-correios-integration.php:141
151
+ msgid "Log %s events, such as WebServices requests."
152
+ msgstr ""
153
+
154
+ #: includes/abstracts/abstract-wc-correios-shipping.php:42
155
+ msgid "%s is a shipping method from Correios."
156
+ msgstr ""
157
+
158
+ #: includes/abstracts/abstract-wc-correios-shipping.php:86
159
+ #: includes/integrations/class-wc-correios-integration.php:63
160
+ msgid "View logs."
161
+ msgstr ""
162
+
163
+ #: includes/abstracts/abstract-wc-correios-shipping.php:124
164
+ msgid "Origin Postcode"
165
+ msgstr ""
166
+
167
+ #: includes/abstracts/abstract-wc-correios-shipping.php:126
168
+ msgid "The postcode of the location your packages are delivered from."
169
+ msgstr ""
170
+
171
+ #: includes/abstracts/abstract-wc-correios-shipping.php:140
172
+ msgid "Additional Days"
173
+ msgstr ""
174
+
175
+ #: includes/abstracts/abstract-wc-correios-shipping.php:142
176
+ msgid "Additional working days to the estimated delivery."
177
+ msgstr ""
178
+
179
+ #: includes/abstracts/abstract-wc-correios-shipping.php:162
180
+ msgid "Receipt Notice"
181
+ msgstr ""
182
+
183
+ #: includes/abstracts/abstract-wc-correios-shipping.php:164
184
+ msgid "Enable receipt notice"
185
+ msgstr ""
186
+
187
+ #: includes/abstracts/abstract-wc-correios-shipping.php:165
188
+ msgid "This controls whether to add costs of the receipt notice service."
189
+ msgstr ""
190
+
191
+ #: includes/abstracts/abstract-wc-correios-shipping.php:170
192
+ msgid "Own Hands"
193
+ msgstr ""
194
+
195
+ #: includes/abstracts/abstract-wc-correios-shipping.php:172
196
+ msgid "Enable own hands"
197
+ msgstr ""
198
+
199
+ #: includes/abstracts/abstract-wc-correios-shipping.php:173
200
+ msgid "This controls whether to add costs of the own hands service"
201
+ msgstr ""
202
+
203
+ #: includes/abstracts/abstract-wc-correios-shipping.php:178
204
+ msgid "Declare Value for Insurance"
205
+ msgstr ""
206
+
207
+ #: includes/abstracts/abstract-wc-correios-shipping.php:180
208
+ msgid "Enable declared value"
209
+ msgstr ""
210
+
211
+ #: includes/abstracts/abstract-wc-correios-shipping.php:181
212
+ msgid ""
213
+ "This controls if the price of the package must be declared for insurance "
214
+ "purposes."
215
+ msgstr ""
216
+
217
+ #: includes/abstracts/abstract-wc-correios-shipping.php:186
218
+ msgid "Service Options"
219
+ msgstr ""
220
+
221
+ #: includes/abstracts/abstract-wc-correios-shipping.php:191
222
+ msgid "Service Code"
223
+ msgstr ""
224
+
225
+ #: includes/abstracts/abstract-wc-correios-shipping.php:193
226
+ msgid "Service code, use this for custom codes."
227
+ msgstr ""
228
+
229
+ #: includes/abstracts/abstract-wc-correios-shipping.php:199
230
+ msgid "Service Type"
231
+ msgstr ""
232
+
233
+ #: includes/abstracts/abstract-wc-correios-shipping.php:201
234
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:136
235
+ msgid "Choose between conventional or corporate service."
236
+ msgstr ""
237
+
238
+ #: includes/abstracts/abstract-wc-correios-shipping.php:206
239
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:140
240
+ msgid "Conventional"
241
+ msgstr ""
242
+
243
+ #: includes/abstracts/abstract-wc-correios-shipping.php:207
244
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:141
245
+ msgid "Corporate"
246
+ msgstr ""
247
+
248
+ #: includes/abstracts/abstract-wc-correios-shipping.php:211
249
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:145
250
+ msgid "Administrative Code"
251
+ msgstr ""
252
+
253
+ #: includes/abstracts/abstract-wc-correios-shipping.php:213
254
+ msgid "Your Correios login. It's usually your CNPJ."
255
+ msgstr ""
256
+
257
+ #: includes/abstracts/abstract-wc-correios-shipping.php:218
258
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:151
259
+ msgid "Administrative Password"
260
+ msgstr ""
261
+
262
+ #: includes/abstracts/abstract-wc-correios-shipping.php:220
263
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:153
264
+ msgid "Your Correios password."
265
+ msgstr ""
266
+
267
+ #: includes/abstracts/abstract-wc-correios-shipping.php:225
268
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:197
269
+ msgid "Package Standard"
270
+ msgstr ""
271
+
272
+ #: includes/abstracts/abstract-wc-correios-shipping.php:227
273
+ msgid "Minimum measure for your shipping packages."
274
+ msgstr ""
275
+
276
+ #: includes/abstracts/abstract-wc-correios-shipping.php:231
277
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:203
278
+ msgid "Minimum Height"
279
+ msgstr ""
280
+
281
+ #: includes/abstracts/abstract-wc-correios-shipping.php:233
282
+ msgid "Minimum height of your shipping packages. Correios needs at least 2cm."
283
+ msgstr ""
284
+
285
+ #: includes/abstracts/abstract-wc-correios-shipping.php:238
286
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:210
287
+ msgid "Minimum Width"
288
+ msgstr ""
289
+
290
+ #: includes/abstracts/abstract-wc-correios-shipping.php:240
291
+ msgid "Minimum width of your shipping packages. Correios needs at least 11cm."
292
+ msgstr ""
293
+
294
+ #: includes/abstracts/abstract-wc-correios-shipping.php:245
295
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:217
296
+ msgid "Minimum Length"
297
+ msgstr ""
298
+
299
+ #: includes/abstracts/abstract-wc-correios-shipping.php:247
300
+ msgid "Minimum length of your shipping packages. Correios needs at least 16cm."
301
+ msgstr ""
302
+
303
+ #: includes/admin/class-wc-correios-admin-orders.php:47
304
+ msgid "Tracking code:"
305
+ msgstr ""
306
+
307
+ #: includes/admin/views/html-admin-help-message.php:14
308
+ msgid ""
309
+ "Help us keep the %s plugin free making a donation or rate "
310
+ "&#9733;&#9733;&#9733;&#9733;&#9733; on WordPress.org. Thank you in advance!"
311
+ msgstr ""
312
+
313
+ #. Plugin Name of the plugin/theme
314
+ msgid "WooCommerce Correios"
315
+ msgstr ""
316
+
317
+ #: includes/admin/views/html-admin-help-message.php:15
318
+ msgid "Make a donation"
319
+ msgstr ""
320
+
321
+ #: includes/admin/views/html-admin-help-message.php:15
322
+ msgid "Make a review"
323
+ msgstr ""
324
+
325
+ #: includes/admin/views/html-admin-missing-dependencies.php:22
326
+ msgid "depends on the last version of WooCommerce to work!"
327
+ msgstr ""
328
+
329
+ #: includes/admin/views/html-admin-missing-dependencies.php:25
330
+ msgid "Active WooCommerce"
331
+ msgstr ""
332
+
333
+ #: includes/admin/views/html-admin-missing-dependencies.php:34
334
+ msgid "Install WooCommerce"
335
+ msgstr ""
336
+
337
+ #: includes/admin/views/html-admin-shipping-method-settings.php:19
338
+ msgid "More about %s."
339
+ msgstr ""
340
+
341
+ #: includes/class-wc-correios-autofill-addresses.php:249
342
+ msgid "Missing postcode paramater."
343
+ msgstr ""
344
+
345
+ #: includes/class-wc-correios-autofill-addresses.php:256
346
+ #: includes/class-wc-correios-autofill-addresses.php:263
347
+ msgid "Invalid postcode."
348
+ msgstr ""
349
+
350
+ #: includes/class-wc-correios-rest-api.php:74
351
+ msgid "Correios tracking code."
352
+ msgstr ""
353
+
354
+ #: includes/emails/class-wc-correios-tracking-email.php:24
355
+ msgid "Correios Tracking Code"
356
+ msgstr ""
357
+
358
+ #: includes/emails/class-wc-correios-tracking-email.php:26
359
+ msgid "This email is sent when configured a tracking code within an order."
360
+ msgstr ""
361
+
362
+ #: includes/emails/class-wc-correios-tracking-email.php:27
363
+ msgid "Your order has been sent"
364
+ msgstr ""
365
+
366
+ #: includes/emails/class-wc-correios-tracking-email.php:28
367
+ msgid "[{site_title}] Your order {order_number} has been sent by Correios"
368
+ msgstr ""
369
+
370
+ #: includes/emails/class-wc-correios-tracking-email.php:29
371
+ msgid "Hi there. Your recent order on {site_title} has been sent by Correios."
372
+ msgstr ""
373
+
374
+ #: includes/emails/class-wc-correios-tracking-email.php:31
375
+ msgid ""
376
+ "To track your delivery, use the following the tracking code: "
377
+ "{tracking_code}."
378
+ msgstr ""
379
+
380
+ #: includes/emails/class-wc-correios-tracking-email.php:33
381
+ msgid ""
382
+ "The delivery service is the responsibility of the Correios, but if you have "
383
+ "any questions, please contact us."
384
+ msgstr ""
385
+
386
+ #: includes/emails/class-wc-correios-tracking-email.php:52
387
+ msgid "Enable this email notification"
388
+ msgstr ""
389
+
390
+ #: includes/emails/class-wc-correios-tracking-email.php:56
391
+ msgid "Subject"
392
+ msgstr ""
393
+
394
+ #: includes/emails/class-wc-correios-tracking-email.php:58
395
+ msgid ""
396
+ "This controls the email subject line. Leave blank to use the default "
397
+ "subject: <code>%s</code>."
398
+ msgstr ""
399
+
400
+ #: includes/emails/class-wc-correios-tracking-email.php:64
401
+ msgid "Email Heading"
402
+ msgstr ""
403
+
404
+ #: includes/emails/class-wc-correios-tracking-email.php:66
405
+ msgid ""
406
+ "This controls the main heading contained within the email. Leave blank to "
407
+ "use the default heading: <code>%s</code>."
408
+ msgstr ""
409
+
410
+ #: includes/emails/class-wc-correios-tracking-email.php:72
411
+ msgid "Email Content"
412
+ msgstr ""
413
+
414
+ #: includes/emails/class-wc-correios-tracking-email.php:74
415
+ msgid ""
416
+ "This controls the initial content of the email. Leave blank to use the "
417
+ "default content: <code>%s</code>."
418
+ msgstr ""
419
+
420
+ #: includes/emails/class-wc-correios-tracking-email.php:80
421
+ msgid "Email type"
422
+ msgstr ""
423
+
424
+ #: includes/emails/class-wc-correios-tracking-email.php:82
425
+ msgid "Choose which format of email to send."
426
+ msgstr ""
427
+
428
+ #: includes/emails/class-wc-correios-tracking-email.php:101
429
+ msgid "Plain text"
430
+ msgstr ""
431
+
432
+ #: includes/emails/class-wc-correios-tracking-email.php:104
433
+ msgid "HTML"
434
+ msgstr ""
435
+
436
+ #: includes/emails/class-wc-correios-tracking-email.php:105
437
+ msgid "Multipart"
438
+ msgstr ""
439
+
440
+ #: includes/integrations/class-wc-correios-integration.php:24
441
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:17
442
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:89
443
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:439
444
+ #: templates/myaccount/tracking-code.php:16
445
+ msgid "Correios"
446
+ msgstr ""
447
+
448
+ #: includes/integrations/class-wc-correios-integration.php:73
449
+ #: includes/integrations/class-wc-correios-integration.php:88
450
+ msgid "Tracking History Table"
451
+ msgstr ""
452
+
453
+ #: includes/integrations/class-wc-correios-integration.php:75
454
+ #: includes/integrations/class-wc-correios-integration.php:93
455
+ msgid ""
456
+ "Displays a table with informations about the shipping in My Account > View "
457
+ "Order page."
458
+ msgstr ""
459
+
460
+ #: includes/integrations/class-wc-correios-integration.php:80
461
+ msgid "Enable Tracking History Table"
462
+ msgstr ""
463
+
464
+ #: includes/integrations/class-wc-correios-integration.php:86
465
+ msgid "Enable logging for Tracking History"
466
+ msgstr ""
467
+
468
+ #: includes/integrations/class-wc-correios-integration.php:91
469
+ #: includes/integrations/class-wc-correios-integration.php:141
470
+ msgid "Autofill Addresses"
471
+ msgstr ""
472
+
473
+ #: includes/integrations/class-wc-correios-integration.php:98
474
+ msgid "Enable Autofill Addresses"
475
+ msgstr ""
476
+
477
+ #: includes/integrations/class-wc-correios-integration.php:102
478
+ msgid "Postcodes Validity"
479
+ msgstr ""
480
+
481
+ #: includes/integrations/class-wc-correios-integration.php:106
482
+ msgid ""
483
+ "Defines how long a postcode will stay saved in the database before a new "
484
+ "query."
485
+ msgstr ""
486
+
487
+ #: includes/integrations/class-wc-correios-integration.php:108
488
+ msgid "1 month"
489
+ msgstr ""
490
+
491
+ #: includes/integrations/class-wc-correios-integration.php:109
492
+ #: includes/integrations/class-wc-correios-integration.php:110
493
+ #: includes/integrations/class-wc-correios-integration.php:111
494
+ #: includes/integrations/class-wc-correios-integration.php:112
495
+ #: includes/integrations/class-wc-correios-integration.php:113
496
+ #: includes/integrations/class-wc-correios-integration.php:114
497
+ #: includes/integrations/class-wc-correios-integration.php:115
498
+ #: includes/integrations/class-wc-correios-integration.php:116
499
+ #: includes/integrations/class-wc-correios-integration.php:117
500
+ #: includes/integrations/class-wc-correios-integration.php:118
501
+ #: includes/integrations/class-wc-correios-integration.php:119
502
+ msgid "%d month"
503
+ msgstr ""
504
+
505
+ #: includes/integrations/class-wc-correios-integration.php:120
506
+ msgid "Forever"
507
+ msgstr ""
508
+
509
+ #: includes/integrations/class-wc-correios-integration.php:124
510
+ msgid "Force Autofill"
511
+ msgstr ""
512
+
513
+ #: includes/integrations/class-wc-correios-integration.php:126
514
+ msgid "Enable Force Autofill"
515
+ msgstr ""
516
+
517
+ #: includes/integrations/class-wc-correios-integration.php:127
518
+ msgid ""
519
+ "When enabled will autofill all addresses after the user finish to fill the "
520
+ "postcode, even if the addresses are already filled."
521
+ msgstr ""
522
+
523
+ #: includes/integrations/class-wc-correios-integration.php:131
524
+ #: includes/integrations/class-wc-correios-integration.php:133
525
+ msgid "Empty Database"
526
+ msgstr ""
527
+
528
+ #: includes/integrations/class-wc-correios-integration.php:134
529
+ msgid ""
530
+ "Delete all the saved postcodes in the database, use this option if you have "
531
+ "issues with outdated postcodes."
532
+ msgstr ""
533
+
534
+ #: includes/integrations/class-wc-correios-integration.php:139
535
+ msgid "Enable logging for Autofill Addresses"
536
+ msgstr ""
537
+
538
+ #: includes/integrations/class-wc-correios-integration.php:160
539
+ msgid ""
540
+ "It's required have installed the %s on your server in order to integrate "
541
+ "with the services of the Correios!"
542
+ msgstr ""
543
+
544
+ #: includes/integrations/class-wc-correios-integration.php:160
545
+ msgid "SOAP module"
546
+ msgstr ""
547
+
548
+ #: includes/integrations/class-wc-correios-integration.php:169
549
+ msgid "Are you sure you want to delete all postcodes from the database?"
550
+ msgstr ""
551
+
552
+ #: includes/integrations/class-wc-correios-integration.php:274
553
+ msgid "Missing parameters!"
554
+ msgstr ""
555
+
556
+ #: includes/integrations/class-wc-correios-integration.php:279
557
+ msgid "Invalid nonce!"
558
+ msgstr ""
559
+
560
+ #: includes/integrations/class-wc-correios-integration.php:288
561
+ msgid "Postcode database emptied successfully!"
562
+ msgstr ""
563
+
564
+ #: includes/shipping/class-wc-correios-shipping-carta-registrada.php:34
565
+ msgid "Carta Registrada"
566
+ msgstr ""
567
+
568
+ #: includes/shipping/class-wc-correios-shipping-esedex.php:34
569
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:189
570
+ msgid "e-SEDEX"
571
+ msgstr ""
572
+
573
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:18
574
+ msgid "Correios is a brazilian delivery method."
575
+ msgstr ""
576
+
577
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:67
578
+ msgid "System Status &gt; Logs"
579
+ msgstr ""
580
+
581
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:92
582
+ msgid "Origin Zip Code"
583
+ msgstr ""
584
+
585
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:94
586
+ msgid "Zip Code from where the requests are sent."
587
+ msgstr ""
588
+
589
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:98
590
+ msgid "Declare value"
591
+ msgstr ""
592
+
593
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:102
594
+ msgid "Declare"
595
+ msgstr ""
596
+
597
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:103
598
+ msgid "None"
599
+ msgstr ""
600
+
601
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:107
602
+ msgid "Estimated delivery"
603
+ msgstr ""
604
+
605
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:109
606
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:159
607
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:167
608
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:175
609
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:183
610
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:191
611
+ msgid "Enable"
612
+ msgstr ""
613
+
614
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:110
615
+ msgid "Display date of estimated delivery."
616
+ msgstr ""
617
+
618
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:115
619
+ msgid "Additional days"
620
+ msgstr ""
621
+
622
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:117
623
+ msgid "Additional days to the estimated delivery."
624
+ msgstr ""
625
+
626
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:130
627
+ msgid "Correios Services"
628
+ msgstr ""
629
+
630
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:134
631
+ msgid "Corporate Service"
632
+ msgstr ""
633
+
634
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:147
635
+ msgid "Your Correios login."
636
+ msgstr ""
637
+
638
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:157
639
+ #: includes/shipping/class-wc-correios-shipping-pac.php:42
640
+ msgid "PAC"
641
+ msgstr ""
642
+
643
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:160
644
+ msgid "Shipping via PAC."
645
+ msgstr ""
646
+
647
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:165
648
+ #: includes/shipping/class-wc-correios-shipping-sedex.php:42
649
+ msgid "SEDEX"
650
+ msgstr ""
651
+
652
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:168
653
+ msgid "Shipping via SEDEX."
654
+ msgstr ""
655
+
656
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:173
657
+ msgid "SEDEX 10"
658
+ msgstr ""
659
+
660
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:176
661
+ msgid "Shipping via SEDEX 10."
662
+ msgstr ""
663
+
664
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:181
665
+ #: includes/shipping/class-wc-correios-shipping-sedex-hoje.php:34
666
+ msgid "SEDEX Hoje"
667
+ msgstr ""
668
+
669
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:184
670
+ msgid "Shipping via SEDEX Hoje."
671
+ msgstr ""
672
+
673
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:192
674
+ msgid "Shipping via e-SEDEX."
675
+ msgstr ""
676
+
677
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:199
678
+ msgid "Sets a minimum measure for the package."
679
+ msgstr ""
680
+
681
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:205
682
+ msgid "Minimum height of the package. Correios needs at least 2 cm."
683
+ msgstr ""
684
+
685
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:212
686
+ msgid "Minimum width of the package. Correios needs at least 11 cm."
687
+ msgstr ""
688
+
689
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:219
690
+ msgid "Minimum length of the package. Correios needs at least 16 cm."
691
+ msgstr ""
692
+
693
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:232
694
+ msgid "Log Correios events, such as WebServices requests, inside %s."
695
+ msgstr ""
696
+
697
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:252
698
+ msgid ""
699
+ "This shipping method this depreciated since %s, and you should configure "
700
+ "shipping methods in the new Shipping Zones screen."
701
+ msgstr ""
702
+
703
+ #: includes/shipping/class-wc-correios-shipping-legacy.php:252
704
+ msgid "See how to configure."
705
+ msgstr ""
706
+
707
+ #: includes/shipping/class-wc-correios-shipping-leve-internacional.php:34
708
+ msgid "Leve Internacional"
709
+ msgstr ""
710
+
711
+ #: includes/shipping/class-wc-correios-shipping-leve-internacional.php:34
712
+ #: includes/shipping/class-wc-correios-shipping-mercadoria-economica.php:34
713
+ #: includes/shipping/class-wc-correios-shipping-mercadoria-expressa.php:34
714
+ msgid "(beta)"
715
+ msgstr ""
716
+
717
+ #: includes/shipping/class-wc-correios-shipping-mercadoria-economica.php:34
718
+ msgid "Mercadoria Econ&ocirc;mica"
719
+ msgstr ""
720
+
721
+ #: includes/shipping/class-wc-correios-shipping-mercadoria-expressa.php:34
722
+ msgid "Mercadoria Expressa"
723
+ msgstr ""
724
+
725
+ #: includes/shipping/class-wc-correios-shipping-sedex10-envelope.php:34
726
+ msgid "SEDEX 10 Envelope"
727
+ msgstr ""
728
+
729
+ #: includes/shipping/class-wc-correios-shipping-sedex10-pacote.php:34
730
+ msgid "SEDEX 10 Pacote"
731
+ msgstr ""
732
+
733
+ #: includes/shipping/class-wc-correios-shipping-sedex12.php:34
734
+ msgid "SEDEX 12"
735
+ msgstr ""
736
+
737
+ #: includes/wc-correios-functions.php:75
738
+ msgid "Delivery within %d working day"
739
+ msgid_plural "Delivery within %d working days"
740
+ msgstr[0] ""
741
+ msgstr[1] ""
742
+
743
+ #: includes/wc-correios-functions.php:106
744
+ msgid "System temporarily down. Please try again later."
745
+ msgstr ""
746
+
747
+ #: includes/wc-correios-functions.php:107
748
+ msgid "Invalid zip code."
749
+ msgstr ""
750
+
751
+ #: includes/wc-correios-functions.php:108
752
+ msgid "Area with delivery temporarily subjected to different periods."
753
+ msgstr ""
754
+
755
+ #: includes/wc-correios-functions.php:147
756
+ msgid "Added a Correios tracking code: %s"
757
+ msgstr ""
758
+
759
+ #: templates/emails/correios-tracking-code.php:19
760
+ #: templates/emails/plain/correios-tracking-code.php:18
761
+ msgid "For your reference, your order details are shown below."
762
+ msgstr ""
763
+
764
+ #: templates/emails/correios-tracking-code.php:23
765
+ msgid "Order:"
766
+ msgstr ""
767
+
768
+ #: templates/emails/correios-tracking-code.php:28
769
+ msgid "Product"
770
+ msgstr ""
771
+
772
+ #: templates/emails/correios-tracking-code.php:29
773
+ msgid "Quantity"
774
+ msgstr ""
775
+
776
+ #: templates/emails/correios-tracking-code.php:30
777
+ msgid "Price"
778
+ msgstr ""
779
+
780
+ #: templates/emails/plain/correios-tracking-code.php:24
781
+ msgid "Order number: %s"
782
+ msgstr ""
783
+
784
+ #: templates/emails/plain/correios-tracking-code.php:25
785
+ msgid "Order date: %s"
786
+ msgstr ""
787
+
788
+ #: templates/myaccount/tracking-code.php:16
789
+ msgid "Your the tracking code:"
790
+ msgstr ""
791
+
792
+ #: templates/myaccount/tracking-history-table.php:15
793
+ msgid "Correios Delivery History"
794
+ msgstr ""
795
+
796
+ #: templates/myaccount/tracking-history-table.php:17
797
+ msgid "History for the tracking code:"
798
+ msgstr ""
799
+
800
+ #: templates/myaccount/tracking-history-table.php:21
801
+ msgid "Date"
802
+ msgstr ""
803
+
804
+ #: templates/myaccount/tracking-history-table.php:22
805
+ msgid "Location"
806
+ msgstr ""
807
+
808
+ #: templates/myaccount/tracking-history-table.php:23
809
+ msgid "Status"
810
+ msgstr ""
811
+
812
+ #: templates/myaccount/tracking-history-table.php:34
813
+ msgid "In transit to %s"
814
+ msgstr ""
815
+
816
+ #. Plugin URI of the plugin/theme
817
+ msgid "https://github.com/claudiosmweb/woocommerce-correios"
818
+ msgstr ""
819
+
820
+ #. Description of the plugin/theme
821
+ msgid "Correios para WooCommerce"
822
+ msgstr ""
823
+
824
+ #. Author of the plugin/theme
825
+ msgid "Claudio Sanches"
826
+ msgstr ""
827
+
828
+ #. Author URI of the plugin/theme
829
+ msgid "http://claudiosmweb.com/"
830
+ msgstr ""
readme.txt ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === WooCommerce Correios ===
2
+ Contributors: claudiosanches, rodrigoprior, matheuscl
3
+ Donate link: http://claudiosmweb.com/doacoes/
4
+ Tags: shipping, delivery, woocommerce, correios
5
+ Requires at least: 4.0
6
+ Tested up to: 4.5
7
+ Stable tag: 3.0.0
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ Integration between the Correios and WooCommerce
12
+
13
+ == Description ==
14
+
15
+ Utilize os métodos de entrega e serviços dos Correios com a sua loja WooCommerce.
16
+
17
+ [Correios](http://www.correios.com.br/) é um método de entrega brasileiro.
18
+
19
+ O plugin WooCommerce Correios foi desenvolvido sem nenhum incentivo dos Correios. Nenhum dos desenvolvedores deste plugin possuem vínculos com esta empresa. E note que este plugin foi feito baseado na documentação do [Webservices Correios](http://www.correios.com.br/webservices/) e com apoio da [Infranology](http://infranology.com.br/) na construção das classes de cubagem.
20
+
21
+ = Serviços integrados =
22
+
23
+ Estão integrados os seguintes serviços:
24
+
25
+ - Entrega nacional:
26
+ - PAC
27
+ - SEDEX
28
+ - SEDEX 10 Envelope
29
+ - SEDEX 10 Pacote
30
+ - SEDEX 12
31
+ - SEDEX Hoje
32
+ - e-SEDEX (necessário conta administrativa nos Correios)
33
+ - Carta Registrada
34
+ - Entrega internacional:
35
+ - Mercadoria Expressa
36
+ - Mercadoria Econômica
37
+ - Leve Internacional
38
+ - Consulta do histórico de rastreamento da encomenda (sendo exibida na página do pedido em "Minha conta" para o cliente)
39
+ - Consulta e autopreenchimento de endereços baseados em CEPs
40
+
41
+ = Instalação: =
42
+
43
+ Confira o nosso guia de instalação e configuração do Correios na aba [Installation](http://wordpress.org/extend/plugins/woocommerce-correios/installation/).
44
+
45
+ = Compatibilidade =
46
+
47
+ Compatível com a versão 2.6.x do WooCommerce.
48
+
49
+ = Dúvidas? =
50
+
51
+ Você pode esclarecer suas dúvidas usando:
52
+
53
+ - A nossa sessão de [FAQ](http://wordpress.org/extend/plugins/woocommerce-correios/faq/).
54
+ - Utilizando o nosso [fórum no Github](https://github.com/claudiosmweb/woocommerce-correios).
55
+ - Criando um tópico no [fórum de ajuda do WordPress](http://wordpress.org/support/plugin/woocommerce-correios).
56
+
57
+ == Installation ==
58
+
59
+ = Instalação do plugin: =
60
+
61
+ - Envie os arquivos do plugin para a pasta wp-content/plugins, ou instale usando o instalador de plugins do WordPress.
62
+ - Ative o plugin.
63
+
64
+ = Requerimentos: =
65
+
66
+ - [SimpleXML](http://php.net/manual/pt_BR/book.simplexml.php) ativado no PHP (note que já é ativado por padrão no PHP 5).
67
+ - Modulo [SOAP](http://php.net/manual/pt_BR/book.soap.php) (utilizado para a tabela de histórico de rastreamento e autopreenchimento de endereços).
68
+
69
+ = Configurações do plugin: =
70
+
71
+ [youtube https://www.youtube.com/watch?v=3z9j0NPU_O0]
72
+
73
+ = Configurações dos produtos =
74
+
75
+ É necessário configurar o **peso** e **dimensões** de todos os seus produtos, caso você queria que a cotação de frete seja exata.
76
+ Note que é possível configurar com produtos do tipo **simples** ou **variável** e não *virtuais* (produtos virtuais são ignorados na hora de cotar o frete).
77
+
78
+ Alternativamente, você pode configurar apenas o peso e deixar as dimensões em branco, pois serão utilizadas as configurações do **Pacote Padrão** para as dimensões (neste caso pode ocorrer uma variação pequena no valor do frete, pois os Correios consideram mais o peso do que as dimensões para a cotação).
79
+
80
+ == Frequently Asked Questions ==
81
+
82
+ = Qual é a licença do plugin? =
83
+
84
+ Este plugin esta licenciado como GPL.
85
+
86
+ = O que eu preciso para utilizar este plugin? =
87
+
88
+ * WooCommerce 2.6 ou superior.
89
+ * [SimpleXML](http://php.net/manual/pt_BR/book.simplexml.php) ativado no PHP (note que já é ativado por padrão no PHP 5).
90
+ * Modulo [SOAP](http://php.net/manual/pt_BR/book.soap.php) (utilizado para a tabela de histórico de rastreamento e autopreenchimento de endereços).
91
+ * Adicionar peso e dimensões nos produtos que pretende entregar.
92
+
93
+ = Quais são os métodos de entrega que o plugin aceita? =
94
+
95
+ São aceitos os seguintes métodos de entrega nacionais:
96
+
97
+ - PAC
98
+ - SEDEX
99
+ - SEDEX 10 Envelope
100
+ - SEDEX 10 Pacote
101
+ - SEDEX 12
102
+ - SEDEX Hoje
103
+ - e-SEDEX (necessário conta administrativa nos Correios)
104
+ - Carta Registrada
105
+
106
+ E os seguintes métodos de entrega internacionais:
107
+
108
+ - Mercadoria Expressa
109
+ - Mercadoria Econômica
110
+ - Leve Internacional
111
+
112
+ = Onde configuro os métodos de entrega? =
113
+
114
+ Os métodos de entrega devem ser configurados em "WooCommerce" > "Configurações" > "Entrega" > "Áreas de entrega".
115
+
116
+ Para entrega nacional, é necessário criar uma área de entrega para o Brasil ou para determinados estados brasileiros e atribuir os métodos de entrega.
117
+
118
+ = Onde configuro o autopreenchimento de endereço ou a tabela de histórico de rastreamento =
119
+
120
+ É possível configurar os dois em "WooCommerce" > "Configurações" > "Integrações" > "Correios".
121
+
122
+ = Como alterar a mensagem que é enviada no e-mail do código de rastreamento? =
123
+
124
+ É possível encontrar configurações para o e-mail do código de rastreamento em "WooCommerce" > "Configurações" > "E-mails" > "Código de rastreio dos Correios".
125
+
126
+ = Como é feita a cotação do frete? =
127
+
128
+ A cotação do frete é feita utilizando o [Calculador Remoto de Preços e Prazos dos Correios](https://www.correios.com.br/para-sua-empresa/servicos-para-o-seu-contrato/precos-e-prazos).
129
+
130
+ Na cotação do frete é usado o seu CEP de origem, CEP de destino do cliente, junto com as dimensões dos produtos e peso. Desta forma o valor cotado sera o mais próximo possível do real.
131
+
132
+ Note que já fazem quase 4 anos que este plugin existe utilizando o mesmo método para obter a cubagem do pedido e tem funcionando muito bem, caso você tenha algum problema, provavelmente é por causa de configurar valores errados nos produtos.
133
+
134
+ = Tem calculadora de frete na página do produto? =
135
+
136
+ Não tem, simplesmente porque não faz parte do escopo deste plugin.
137
+
138
+ Escopo deste plugin é prover integração entre o WooCommerce e os Correios.
139
+
140
+ = Este plugin faz alterações na calculadora de frete na página do carrinho ou na de finalização? =
141
+
142
+ Não, nenhuma alteração é feita, este plugin funcionando esperando o WooCommerce verificar pelos valores de entrega, então é feita uma conexão com os Correios e os valores retornados são passados de volta para o WooCommerce apresentar.
143
+
144
+ Note que não damos suporte para qualquer tipo de personalização na calculadora, simplesmente porque não faz parte do escopo do plugin, caso você queria mudar algo como aparece, deve procurar ajuda com o WooCommerce e não com este plugin.
145
+
146
+ = Como resolver o erro "Não existe nenhum método de entrega disponível. Por favor, certifique-se de que o seu endereço esta correto ou entre em contato conosco caso você precise de ajuda."? =
147
+
148
+ Primeiro de tudo, isso não é um erro, isso é uma mensagem padrão do WooCommerce que é exibida quando não é encontrado nenhuma método de entrega.
149
+
150
+ Mesmo você configurando os métodos de entrega, eles não são exibidos quando os Correios retornam mensagens de erro, por exemplo quando a região onde o cliente esta não é coberta pelos Correios ou quando o peso do pacote passa do limite suportado.
151
+
152
+ Entretanto boa parte das vezes esse tipo de coisa acontece porque os métodos e/ou produtos não foram configurados corretamente.
153
+
154
+ Aqui uma lista de erros mais comuns:
155
+
156
+ - Faltando CEP de origem nos métodos configurados.
157
+ - CEP de origem inválido.
158
+ - Produtos cadastrados sem peso e dimensões
159
+ - Peso e dimensões cadastrados de forma incorreta (por exemplo configurando como 1000kg, pensando que seria 1000g, então verifique as configurações de medidas em `WooCommerce > Configurações > Produtos`).
160
+
161
+ E não se esqueça de verificar o erro ativando a opção de **Log de depuração** nas configurações de cada método de entrega. Imediatamente após ativar o log, basta tentar cotar o frete novamente, fazendo assim o log ser gerado. Você pode acessar todos os logs indo em "WooCommerce" > "Status do sistema" > "Logs".
162
+
163
+ Dica: Caso apareça no log a mensagem `WP_Error: connect() timed out!` pode acontecer do site dos Correios ter caído ou o seu servidor estar com pouca memoria.
164
+
165
+ = Os métodos de entrega dos Correios não aparecem no carrinho ou durante a finalização? =
166
+
167
+ As mesmas dicas da sessão acima valem como solução para isto também.
168
+
169
+ = O valor do frete calculado não bateu com a da loja dos Correios? =
170
+
171
+ Este plugin utiliza o Webservices dos Correios para calcular o frete e quando este tipo de problema acontece geralmente é porque:
172
+
173
+ 1. Foram configuradas de forma errada as opções de peso e dimensões dos produtos na loja.
174
+ 2. Configurado errado o CEP de origem nos métodos de entrega.
175
+ 3. O Webservices dos Correios enviou um valor errado! Sim isso acontece e na página da documentação do Webservice tem o seguinte alerta:
176
+
177
+ > Os valores obtidos pelos simuladores aqui disponíveis são uma estimativa e deverão ser confirmados no ato da postagem.
178
+
179
+ = Ainda esta tendo problemas? =
180
+
181
+ Se estiver tendo problemas, antes de tudo ative a opção de **Log de depuração** do método que você esta tendo problema e tente novamente cotar o frete, fazendo isso, um arquivo de log é criado e são registradas as respostas do Webservice dos Correios, leia o arquivo de log, nele é descrito exatamente o que esta acontecendo, tanto o que foi concluindo com sucesso ou não.
182
+
183
+ Se ainda não foi capaz de solucionar o problema, copie o conteúdo do arquivo de log, cole no [pastebin.com](http://pastebin.com), salve e pegue o link gerado, depois disso abra um tópico informando o seu problema no [fórum de suporte do plugin](https://wordpress.org/support/plugin/woocommerce-correios#postform).
184
+
185
+ = Dúvidas sobre o funcionamento do plugin? =
186
+
187
+ Em caso de dúvidas, basta abrir um tópico no [fórum de suporte do plugin](https://wordpress.org/support/plugin/woocommerce-correios#postform), vou responder conforme eu tenho tempo livre e caso sua dúvida for relacionada com o funcionamento deste plguin.
188
+
189
+ == Screenshots ==
190
+
191
+ 1. Exemplo de áreas de entrega com os Correios.
192
+ 2. Exemplo da tela de configurações dos métodos de entrega.
193
+ 3. Configurações de integração com os Correios.
194
+ 4. Campo para adicionar o código de rastreamento (tela de administração de pedidos).
195
+ 5. Configurações do e-mails do código de rastreamento.
196
+ 6. Exemplo dos métodos de entrega sendo exibidos na página de finalização.
197
+ 7. Exemplo do código de rastreamento sendo exibido dentro da página de detalhes de pedido na página "Minha conta".
198
+ 8. Exemplo da tabela do histórico de rastreamento que é exibida no lugar do alerta acima quando ativada a opção "Tabela do histórico de rastreamento" nas configurações de integração.
199
+
200
+ == Changelog ==
201
+
202
+ = 3.0.0 - 2016/06/26 =
203
+
204
+ - Reformulação geral de todos o código do plugin.
205
+ - Adicionado suporte as áreas de entrega do WooCommerce 2.6.
206
+ - Adicionado os métodos de SEDEX 10 Envelope, SEDEX 12, Carta Registrada, Mercadoria Expressa, Mercadoria Econômica e Leve Internacional.
207
+ - Adicionado novo menu de "integrações".
208
+ - Adicionada integração com o serviço de consulta de CEP e assim adicionando uma opção para autopreencher endereços com base no CEP.
209
+ - Atualizada a integração com o sistema que gera o histórico de rastreamento do pedido.
210
+ - Removida a opção de simulador de frete do carrinho.
211
+ - Integrado o campo de "correios_tracking_code" dos pedidos com a API REST do WooCommerce.
212
+ - E mais outras várias alterações que podem ser verificadas pelo [GitHub](https://github.com/claudiosmweb/woocommerce-correios/compare/2.3.0...3.0.0).
213
+
214
+ == Upgrade Notice ==
215
+
216
+ = 3.0.0 =
217
+
218
+ - Reformulação geral de todos o código do plugin.
219
+ - Adicionado suporte as áreas de entrega do WooCommerce 2.6.
220
+ - Adicionado os métodos de SEDEX 10 Envelope, SEDEX 12, Carta Registrada, Mercadoria Expressa, Mercadoria Econômica e Leve Internacional.
221
+ - Adicionado novo menu de "integrações".
222
+ - Adicionada integração com o serviço de consulta de CEP e assim adicionando uma opção para autopreencher endereços com base no CEP.
223
+ - Atualizada a integração com o sistema que gera o histórico de rastreamento do pedido.
224
+ - Removida a opção de simulador de frete do carrinho.
225
+ - Integrado o campo de "correios_tracking_code" dos pedidos com a API REST do WooCommerce.
226
+ - E mais outras várias alterações que podem ser verificadas pelo [GitHub](https://github.com/claudiosmweb/woocommerce-correios/compare/2.3.0...3.0.0).
templates/emails/correios-tracking-code.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Tracking code HTML email notification.
4
+ *
5
+ * @author Claudio_Sanches
6
+ * @package WooCommerce_Correios/Templates
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+ ?>
14
+
15
+ <?php do_action( 'woocommerce_email_header', $email_heading ); ?>
16
+
17
+ <?php echo wptexturize( wpautop( $tracking_message ) ); ?>
18
+
19
+ <p><?php esc_html_e( 'For your reference, your order details are shown below.', 'woocommerce-correios' ); ?></p>
20
+
21
+ <?php do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text ); ?>
22
+
23
+ <h2><?php echo esc_html( __( 'Order:', 'woocommerce-correios' ) . ' ' . $order->get_order_number() ); ?></h2>
24
+
25
+ <table cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">
26
+ <thead>
27
+ <tr>
28
+ <th scope="col" style="text-align:left; border: 1px solid #eee;"><?php esc_html_e( 'Product', 'woocommerce-correios' ); ?></th>
29
+ <th scope="col" style="text-align:left; border: 1px solid #eee;"><?php esc_html_e( 'Quantity', 'woocommerce-correios' ); ?></th>
30
+ <th scope="col" style="text-align:left; border: 1px solid #eee;"><?php esc_html_e( 'Price', 'woocommerce-correios' ); ?></th>
31
+ </tr>
32
+ </thead>
33
+ <tbody>
34
+ <?php
35
+ if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.5', '>=' ) ) {
36
+ echo $order->email_order_items_table( array(
37
+ 'plain_text' => false,
38
+ ) );
39
+ } else {
40
+ echo $order->email_order_items_table( true, false, true );
41
+ }
42
+ ?>
43
+ </tbody>
44
+ <tfoot>
45
+ <?php if ( $totals = $order->get_order_item_totals() ) :
46
+ $i = 0;
47
+ foreach ( $totals as $total ) :
48
+ $i++;
49
+ ?>
50
+ <tr>
51
+ <th scope="row" colspan="2" style="text-align: left; border: 1px solid #eee; <?php echo ( 1 == $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo $total['label']; ?></th>
52
+ <td style="text-align: left; border: 1px solid #eee; <?php echo ( 1 == $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo $total['value']; ?></td>
53
+ </tr>
54
+ <?php
55
+ endforeach;
56
+ endif; ?>
57
+ </tfoot>
58
+ </table>
59
+
60
+ <?php do_action( 'woocommerce_email_after_order_table', $order, $sent_to_admin, $plain_text ); ?>
61
+
62
+ <?php
63
+
64
+ /**
65
+ * Order meta.
66
+ *
67
+ * @hooked WC_Emails::order_meta() Shows order meta data.
68
+ */
69
+ do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text );
70
+
71
+ /**
72
+ * Customer details.
73
+ *
74
+ * @hooked WC_Emails::customer_details() Shows customer details
75
+ * @hooked WC_Emails::email_address() Shows email address
76
+ */
77
+ do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text );
78
+
79
+ /**
80
+ * Email footer.
81
+ *
82
+ * @hooked WC_Emails::email_footer() Output the email footer.
83
+ */
84
+ do_action( 'woocommerce_email_footer' );
templates/emails/plain/correios-tracking-code.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Tracking code plain email notification.
4
+ *
5
+ * @author Claudio_Sanches
6
+ * @package WooCommerce_Correios/Templates
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ echo '= ' . $email_heading . " =\n\n";
15
+
16
+ echo wptexturize( $tracking_message ) . "\n\n";
17
+
18
+ echo __( 'For your reference, your order details are shown below.', 'woocommerce-correios' ) . "\n\n";
19
+
20
+ echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
21
+
22
+ do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text );
23
+
24
+ printf( __( 'Order number: %s', 'woocommerce-correios' ), $order->get_order_number() ) . "\n";
25
+ printf( __( 'Order date: %s', 'woocommerce-correios' ), date_i18n( wc_date_format(), strtotime( $order->order_date ) ) ) . "\n";
26
+
27
+ do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text );
28
+
29
+ if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.5', '>=' ) ) {
30
+ $order_items = $order->email_order_items_table( array(
31
+ 'plain_text' => true,
32
+ ) );
33
+ } else {
34
+ $order_items = $order->email_order_items_table( true, false, true, '', '', true );
35
+ }
36
+
37
+ echo "\n" . $order_items;
38
+
39
+ echo "----------\n\n";
40
+
41
+ if ( $totals = $order->get_order_item_totals() ) {
42
+ foreach ( $totals as $total ) {
43
+ echo $total['label'] . "\t " . $total['value'] . "\n";
44
+ }
45
+ }
46
+
47
+ do_action( 'woocommerce_email_after_order_table', $order, $sent_to_admin, $plain_text );
48
+
49
+ echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
50
+
51
+ /**
52
+ * Order meta.
53
+ *
54
+ * @hooked WC_Emails::order_meta() Shows order meta data.
55
+ */
56
+ do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text );
57
+
58
+ /**
59
+ * Customer details.
60
+ *
61
+ * @hooked WC_Emails::customer_details() Shows customer details.
62
+ * @hooked WC_Emails::email_address() Shows email address.
63
+ */
64
+ do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text );
65
+
66
+ echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
67
+
68
+ echo apply_filters( 'woocommerce_email_footer_text', get_option( 'woocommerce_email_footer_text' ) );
templates/myaccount/tracking-code.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Tracking code.
4
+ *
5
+ * @author Claudio_Sanches
6
+ * @package WooCommerce_Correios/Templates
7
+ * @version 2.2.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+ ?>
14
+
15
+ <div id="wc-correios-tracking" class="woocommerce-info">
16
+ <strong><?php esc_html_e( 'Correios', 'woocommerce-correios' ); ?>:</strong> <?php esc_html_e( 'Your the tracking code:', 'woocommerce-correios' ); ?> <a href="http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_TIPO=001&P_COD_UNI=<?php echo esc_attr( $code ); ?>" target="_blank"><?php echo esc_html( $code ) ?></a>.
17
+ </div>
templates/myaccount/tracking-history-table.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Tracking history table.
4
+ *
5
+ * @author Claudio_Sanches
6
+ * @package WooCommerce_Correios/Templates
7
+ * @version 2.2.0
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+ ?>
14
+
15
+ <h2 id="wc-correios-tracking"><?php esc_html_e( 'Correios Delivery History', 'woocommerce-correios' ); ?></h2>
16
+
17
+ <p><?php esc_html_e( 'History for the tracking code:', 'woocommerce-correios' ); ?> <a href="http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_TIPO=001&P_COD_UNI=<?php echo esc_attr( $code ); ?>" target="_blank"><?php echo esc_html( $code ) ?></a>.</p>
18
+
19
+ <table class="shop_table shop_table_responsive">
20
+ <tr>
21
+ <th><?php esc_html_e( 'Date', 'woocommerce-correios' ); ?></th>
22
+ <th><?php esc_html_e( 'Location', 'woocommerce-correios' ); ?></th>
23
+ <th><?php esc_html_e( 'Status', 'woocommerce-correios' ); ?></th>
24
+ </tr>
25
+
26
+ <?php foreach ( $events as $event ) : ?>
27
+ <tr>
28
+ <td><?php echo esc_html( $event->data . ' ' . $event->hora ); ?></td>
29
+ <td>
30
+ <?php echo esc_html( $event->local . ' - ' . $event->cidade . '/' . $event->uf ); ?>
31
+
32
+ <?php if ( isset( $event->destino ) ) : ?>
33
+ <br />
34
+ <?php echo esc_html( sprintf( __( 'In transit to %s', 'woocommerce-correios' ), $event->destino->local . ' - ' . $event->destino->cidade . '/' . $event->destino->uf ) ); ?>
35
+ <?php endif; ?>
36
+ </td>
37
+ <td>
38
+ <?php echo esc_html( $event->descricao ); ?>
39
+ </td>
40
+ </tr>
41
+ <?php endforeach; ?>
42
+ </table>
uninstall.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Correios Uninstall
4
+ *
5
+ * @package WooCommerce_Correios/Uninstaller
6
+ * @since 3.0.0
7
+ * @version 3.0.0
8
+ */
9
+
10
+ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
11
+ exit;
12
+ }
13
+
14
+ global $wpdb;
15
+
16
+ $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}correios_postcodes" );
wc-correios.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Update main file for legacy from installations.
4
+ *
5
+ * @package WooCommerce_Correios
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+ // Update the main file.
13
+ $active_plugins = get_option( 'active_plugins', array() );
14
+
15
+ foreach ( $active_plugins as $key => $active_plugin ) {
16
+ if ( strstr( $active_plugin, '/wc-correios.php' ) ) {
17
+ $active_plugins[ $key ] = str_replace( '/wc-correios.php', '/woocommerce-correios.php', $active_plugin );
18
+ }
19
+ }
20
+
21
+ update_option( 'active_plugins', $active_plugins );
woocommerce-correios.php ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: WooCommerce Correios
4
+ * Plugin URI: https://github.com/claudiosmweb/woocommerce-correios
5
+ * Description: Correios para WooCommerce
6
+ * Author: Claudio Sanches
7
+ * Author URI: http://claudiosmweb.com/
8
+ * Version: 3.0.0
9
+ * License: GPLv2 or later
10
+ * Text Domain: woocommerce-correios
11
+ * Domain Path: languages/
12
+ *
13
+ * @package WooCommerce_Correios
14
+ */
15
+
16
+ if ( ! defined( 'ABSPATH' ) ) {
17
+ exit; // Exit if accessed directly.
18
+ }
19
+
20
+ if ( ! class_exists( 'WC_Correios' ) ) :
21
+
22
+ /**
23
+ * WooCommerce Correios main class.
24
+ */
25
+ class WC_Correios {
26
+
27
+ /**
28
+ * Plugin version.
29
+ *
30
+ * @var string
31
+ */
32
+ const VERSION = '3.0.0';
33
+
34
+ /**
35
+ * Instance of this class.
36
+ *
37
+ * @var object
38
+ */
39
+ protected static $instance = null;
40
+
41
+ /**
42
+ * Initialize the plugin public actions.
43
+ */
44
+ private function __construct() {
45
+ add_action( 'init', array( $this, 'load_plugin_textdomain' ), -1 );
46
+
47
+ // Checks with WooCommerce is installed.
48
+ if ( class_exists( 'WC_Integration' ) ) {
49
+ $this->includes();
50
+
51
+ if ( is_admin() ) {
52
+ $this->admin_includes();
53
+ }
54
+
55
+ add_filter( 'woocommerce_integrations', array( $this, 'include_integrations' ) );
56
+ add_filter( 'woocommerce_shipping_methods', array( $this, 'include_methods' ) );
57
+ add_filter( 'woocommerce_email_classes', array( $this, 'include_emails' ) );
58
+ } else {
59
+ add_action( 'admin_notices', array( $this, 'woocommerce_missing_notice' ) );
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Return an instance of this class.
65
+ *
66
+ * @return object A single instance of this class.
67
+ */
68
+ public static function get_instance() {
69
+ // If the single instance hasn't been set, set it now.
70
+ if ( null == self::$instance ) {
71
+ self::$instance = new self;
72
+ }
73
+
74
+ return self::$instance;
75
+ }
76
+
77
+ /**
78
+ * Load the plugin text domain for translation.
79
+ */
80
+ public function load_plugin_textdomain() {
81
+ load_plugin_textdomain( 'woocommerce-correios', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
82
+ }
83
+
84
+ /**
85
+ * Includes.
86
+ */
87
+ private function includes() {
88
+ include_once dirname( __FILE__ ) . '/includes/wc-correios-functions.php';
89
+ include_once dirname( __FILE__ ) . '/includes/class-wc-correios-install.php';
90
+ include_once dirname( __FILE__ ) . '/includes/class-wc-correios-package.php';
91
+ include_once dirname( __FILE__ ) . '/includes/class-wc-correios-webservice.php';
92
+ include_once dirname( __FILE__ ) . '/includes/class-wc-correios-webservice-international.php';
93
+ include_once dirname( __FILE__ ) . '/includes/class-wc-correios-autofill-addresses.php';
94
+ include_once dirname( __FILE__ ) . '/includes/class-wc-correios-tracking-history.php';
95
+ include_once dirname( __FILE__ ) . '/includes/class-wc-correios-rest-api.php';
96
+
97
+ // Integration.
98
+ include_once dirname( __FILE__ ) . '/includes/integrations/class-wc-correios-integration.php';
99
+
100
+ // Shipping methods.
101
+ if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.6.0', '>=' ) ) {
102
+ include_once dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-correios-shipping.php';
103
+ include_once dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-correios-international-shipping.php';
104
+ foreach ( glob( plugin_dir_path( __FILE__ ) . '/includes/shipping/*.php' ) as $filename ) {
105
+ include_once $filename;
106
+ }
107
+
108
+ // Update settings to 3.0.0 when using WooCommerce 2.6.0.
109
+ WC_Correios_Install::upgrade_300_to_wc_260();
110
+ } else {
111
+ include_once dirname( __FILE__ ) . '/includes/shipping/class-wc-correios-shipping-legacy.php';
112
+ }
113
+
114
+ // Update to 3.0.0.
115
+ WC_Correios_Install::upgrade_300();
116
+ }
117
+
118
+ /**
119
+ * Admin includes.
120
+ */
121
+ private function admin_includes() {
122
+ include_once dirname( __FILE__ ) . '/includes/admin/class-wc-correios-admin-orders.php';
123
+ }
124
+
125
+ /**
126
+ * Include Correios integration to WooCommerce.
127
+ *
128
+ * @param array $integrations Default integrations.
129
+ *
130
+ * @return array
131
+ */
132
+ public function include_integrations( $integrations ) {
133
+ $integrations[] = 'WC_Correios_Integration';
134
+
135
+ return $integrations;
136
+ }
137
+
138
+ /**
139
+ * Include Correios shipping methods to WooCommerce.
140
+ *
141
+ * @param array $methods Default shipping methods.
142
+ *
143
+ * @return array
144
+ */
145
+ public function include_methods( $methods ) {
146
+ // Legacy method.
147
+ $methods['correios-legacy'] = 'WC_Correios_Shipping_Legacy';
148
+
149
+ // New methods.
150
+ if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.6.0', '>=' ) ) {
151
+ $methods['correios-pac'] = 'WC_Correios_Shipping_PAC';
152
+ $methods['correios-sedex'] = 'WC_Correios_Shipping_SEDEX';
153
+ $methods['correios-sedex10-envelope'] = 'WC_Correios_Shipping_SEDEX_10_Envelope';
154
+ $methods['correios-sedex10-pacote'] = 'WC_Correios_Shipping_SEDEX_10_Pacote';
155
+ $methods['correios-sedex12'] = 'WC_Correios_Shipping_SEDEX_12';
156
+ $methods['correios-sedex-hoje'] = 'WC_Correios_Shipping_SEDEX_Hoje';
157
+ $methods['correios-esedex'] = 'WC_Correios_Shipping_ESEDEX';
158
+ $methods['correios-carta-registrada'] = 'WC_Correios_Shipping_Carta_Registrada';
159
+ $methods['correios-mercadoria-expressa'] = 'WC_Correios_Shipping_Mercadoria_Expressa';
160
+ $methods['correios-mercadoria-economica'] = 'WC_Correios_Shipping_Mercadoria_Economica';
161
+ $methods['correios-leve-internacional'] = 'WC_Correios_Shipping_Leve_Internacional';
162
+
163
+ $old_options = get_option( 'woocommerce_correios_settings' );
164
+ if ( empty( $old_options ) ) {
165
+ unset( $methods['correios-legacy'] );
166
+ }
167
+ }
168
+
169
+ return $methods;
170
+ }
171
+
172
+ /**
173
+ * Include emails.
174
+ *
175
+ * @param array $emails Default emails.
176
+ *
177
+ * @return array
178
+ */
179
+ public function include_emails( $emails ) {
180
+ if ( ! isset( $emails['WC_Correios_Tracking_Email'] ) ) {
181
+ $emails['WC_Correios_Tracking_Email'] = include( dirname( __FILE__ ) . '/includes/emails/class-wc-correios-tracking-email.php' );
182
+ }
183
+
184
+ return $emails;
185
+ }
186
+
187
+ /**
188
+ * WooCommerce fallback notice.
189
+ */
190
+ public function woocommerce_missing_notice() {
191
+ include_once dirname( __FILE__ ) . '/includes/admin/views/html-admin-missing-dependencies.php';
192
+ }
193
+
194
+ /**
195
+ * Get main file.
196
+ *
197
+ * @return string
198
+ */
199
+ public static function get_main_file() {
200
+ return __FILE__;
201
+ }
202
+
203
+ /**
204
+ * Get plugin path.
205
+ *
206
+ * @return string
207
+ */
208
+ public static function get_plugin_path() {
209
+ return plugin_dir_path( __FILE__ );
210
+ }
211
+
212
+ /**
213
+ * Get templates path.
214
+ *
215
+ * @return string
216
+ */
217
+ public static function get_templates_path() {
218
+ return self::get_plugin_path() . 'templates/';
219
+ }
220
+ }
221
+
222
+ add_action( 'plugins_loaded', array( 'WC_Correios', 'get_instance' ) );
223
+
224
+ endif;