forked from krokedil/paysoncheckout-for-woocommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkrokedil-wc-compatability.php
139 lines (127 loc) · 3.41 KB
/
krokedil-wc-compatability.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/**
*
* Functions to make plugin compatible with multiple versions of WooCommerce
*
*/
// Get the current WooCommerce version.
if ( ! function_exists( 'krokedil_get_wc_version' ) ) {
function krokedil_get_wc_version() {
return defined( 'WC_VERSION' ) && WC_VERSION ? WC_VERSION : null;
}
}
// Check if WooCommerce version is greater or equal to 3.0
if ( ! function_exists( 'krokedil_wc_gte_3_0' ) ) {
function krokedil_wc_gte_3_0() {
return krokedil_get_wc_version() && version_compare( krokedil_get_wc_version(), '3.0', '>=' );
}
}
// Get the order total
if ( ! function_exists( 'krokedil_get_order_total' ) ) {
function krokedil_get_order_total( $order ) {
if ( krokedil_wc_gte_3_0() ) {
return $order->get_total();
} else {
return $order->order_total;
}
}
}
if ( ! function_exists( 'krokedil_get_billing_email' ) ) {
// Get the billing email
function krokedil_get_billing_email( $order ) {
if ( krokedil_wc_gte_3_0() ) {
return $order->get_billing_email();
} else {
return $order->billing_email;
}
}
}
if ( ! function_exists( 'krokedil_get_billing_first_name' ) ) {
// Get the billing first name
function krokedil_get_billing_first_name( $order ) {
if ( krokedil_wc_gte_3_0() ) {
return $order->get_billing_first_name();
} else {
return $order->billing_first_name;
}
}
}
if ( ! function_exists( 'krokedil_get_billing_last_name' ) ) {
// Get the billing last name
function krokedil_get_billing_last_name( $order ) {
if ( krokedil_wc_gte_3_0() ) {
return $order->get_billing_last_name();
} else {
return $order->billing_last_name;
}
}
}
if ( ! function_exists( 'krokedil_get_order_shipping_tax' ) ) {
// Get the shipping tax
function krokedil_get_order_shipping_tax( $order ) {
if ( krokedil_wc_gte_3_0() ) {
return $order->get_shipping_tax();
} else {
return $order->order_shipping_tax;
}
}
}
if ( ! function_exists( 'krokedil_get_product_id' ) ) {
// Get the product id
function krokedil_get_product_id( $product ) {
if ( krokedil_wc_gte_3_0() ) {
return $product->get_id();
} else {
return $product->id;
}
}
}
if ( ! function_exists( 'krokedil_get_order_id' ) ) {
// Get the order id
function krokedil_get_order_id( $order ) {
if ( krokedil_wc_gte_3_0() ) {
return $order->get_id();
} else {
return $order->id;
}
}
}
if ( ! function_exists( 'krokedil_get_item_meta_cart' ) ) {
// Get item meta
function krokedil_get_item_meta_cart( $item, $product ) {
if ( krokedil_wc_gte_3_0() ) {
$item_meta = '';
} else {
$item_meta = new WC_Order_Item_Meta( $item['item_meta'], $product );
$item_meta = nl2br( $item_meta->display( true, true ) );
}
return $item_meta;
}
}
if ( ! function_exists( 'krokedil_get_item_meta_order' ) ) {
function krokedil_get_item_meta_order( $item, $product ) {
if ( krokedil_wc_gte_3_0() ) {
$item_meta = strip_tags( wc_display_item_meta( $item, array(
'before' => '',
'separator' => ', ',
'after' => '',
'echo' => false,
'autop' => false,
) ) );
return $item_meta;
} else {
$item_meta = new WC_Order_Item_Meta( $item['item_meta'], $product );
$item_meta = nl2br( $item_meta->display( true, true ) );
return $item_meta;
}
}
}
if ( ! function_exists( 'krokedil_get_payment_method' ) ) {
function krokedil_get_payment_method( $order ) {
if ( krokedil_wc_gte_3_0() ) {
return $order->get_payment_method();
} else {
return $order->payment_method;
}
}
}