-
Notifications
You must be signed in to change notification settings - Fork 0
/
wcc-order-status.php
86 lines (74 loc) · 2.17 KB
/
wcc-order-status.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/*
* Plugin Name: WC Correios Order Status
* Description: Visual way to keep track of your Correios order status on client-end!
* Author: Matheus Pratta
* Author URI: https://matheus.io
* Version: 1.0
* Requires at least: 4.2
* Tested up to: 4.9.4
* WC requires at least: 3.0
* WC tested up to: 3.3.1
* License: GPL2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
require_once ('rastrear.class.php');
function wccos_get_status ($order) {
// Is the order complete?
if ($order->status == 'completed')
return 3;
// If not, is it paid?
else if ($order->status == 'processing') {
// Get the Correios tracking info
$tracking_id = get_post_meta($order->id, '_correios_tracking_code');
// If we have a tracking code, try to find out order status
if (!empty($tracking_id) && count($tracking_id) && !empty($tracking_id[0])) {
// Correios API init
Rastrear::init();
// Get tracking data
$tracking_data = Rastrear::get($tracking_id[0]);
// Check if status is delivered (01)
if ($tracking_data->evento->status == '01')
return 3;
return 2;
}
// If not, return 0
else
return 1;
}
// If not paid
else
return 0;
}
function wccos_display_status ($order) {
// Initial status
$status = wccos_get_status($order);
// All Statuses
$statuses = array(
0 => 'Aguardando Pagamento',
1 => 'Pagamento Aprovado',
2 => 'Produto Enviado',
3 => 'Produto Entregue'
);
?>
<div class="wccos-order-status">
<table>
<tr>
<?php foreach ($statuses as $n => $text) { ?>
<td class="<?php if ($n <= $status) { ?>enabled<?php } ?>">
<div><?php echo $text; ?></div>
</td>
<?php } ?>
</tr>
</table>
</div>
<?php }
// Enqueue into WooCommerce
add_action ( 'woocommerce_order_details_before_order_table', 'wccos_display_status' );
wp_enqueue_style ( 'wccos-order-status', plugins_url( '/wcc-order-status.css', __FILE__ ) );
// Plugin stuff :)
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'wcc_plugin_links' );
function wcc_plugin_links ( $links ) {
$links[] = '<a href="https://github.com/MatheusMK3/wcc-order-status" target="_blank" title="Star this plugin on GitHub! <3">GitHub</a>';
return $links;
}