recurring-totals.php
13.9 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<?php
/**
* Recurring totals
*
* @author Prospress
* @package WooCommerce Subscriptions/Templates
* @version 2.0
*/
if (!defined('ABSPATH')) {
exit;
}
global $wpdb;
$display_th = true;
$isUpgrade = false;
$cart_content = WC()->cart->cart_contents;
if (count($cart_content) > 0) {
$shipping_cost = 0;
$upgrade_total = 0;
$number_drink = 0;
foreach ($recurring_carts as $_key => $_value) {
$upgrade_total = $_value->total - $_value->shipping_total;
}
foreach ($cart_content as $key => $value) {
if (isset($value['subscription_switch'])) {
// var_dump($value['variation_id']);
$number_drink = $value['variation']['attribute_drinks'];
$isUpgrade = true;
$weight = get_post_meta($value['variation_id'], '_weight')[0];
if ($weight == '') {
$weight = get_post_meta($value['product_id'], '_weight')[0];
}
$weight = (float) $weight;
$result_shipping_zones = get_option('be_woocommerce_shipping_zones');
$shipping_country = $_POST['s_country'];
if (count($result_shipping_zones)) {
foreach ($result_shipping_zones as $value) {
if ($value['zone_country'] == $shipping_country) {
$zone_id = $value['zone_id'];
}
}
}
if (isset($zone_id)) {
$result_shipping_rates_table = get_option('woocommerce_table_rates');
// var_dump($result_shipping_rates_table);
foreach ($result_shipping_rates_table as $value) {
if ($value['zone'] == $zone_id && $value['cond'] == 'weight') {
if ($weight >= $value['min'] && $weight <= $value['max']) {
$shipping_cost = $value['cost'];
// $shipping_label = $value['title'];
}
}
}
$shipping_label = $woocommerce->countries->countries[$shipping_country];
}
}
}
}
$upgrade_total = $upgrade_total + $shipping_cost;
?>
<?php
if ($isUpgrade) {
?>
<tr class="shipping shipping-upgrade text-uppercase robotoregular">
<th class="font18">SHIPPING</th>
<td class="font18 text-right fontbold">
<?php
if ($shipping_cost == 0) {
echo "Free";
} else {
echo wc_price($shipping_cost);
}
//echo wp_kses_post(wcs_cart_totals_shipping_method($shipping_method, $recurring_carts[$recurring_cart_key]));
?>
</td>
</tr>
<script>
jQuery(document).ready(function ($) {
$('.shipping-upgrade').insertBefore($('.order-total.tvhide '));
$('.order-total.tvhide .amount').html('$<?php echo number_format($upgrade_total, 2) ?>');
if ($('.message_upgrade').length > 0) {
$('.message_upgrade').html('Fill out details below and press checkout.<br/>The monthly payment for your new subscription of <?php echo $number_drink; ?> drinks will now be $<?php echo number_format($upgrade_total, 2) ?> - deducted on your regular billing date.');
}
else {
$('.woocommerce-checkout-payment .place-order').append('<span class="message_upgrade">Fill out details below and press checkout.<br/>The monthly payment for your new subscription of <?php echo $number_drink; ?> drinks will now be $<?php echo number_format($upgrade_total, 2) ?> - deducted on your regular billing date.</span>');
}
});
</script>
<?php
}
?>
<tr class="recurring-totals tvhide">
<th colspan="2"><?php esc_html_e('Recurring Totals', 'woocommerce-subscriptions'); ?></th>
</tr>
<?php if (WC()->cart->needs_shipping() && WC()->cart->show_shipping() && !empty($shipping_methods)) : ?>
<?php
$ii = 0;
foreach ($shipping_methods as $recurring_cart_key => $shipping_method) :
if ($recurring_cart_key != 'table_rate_shipping') {
continue;
}
//if ($ii == 0) {
?>
<tr class="shipping recurring-total text-uppercase robotoregular <?php echo $ii; ?> shippingwcs">
<td class="desktop carthide"> </td>
<?php if ($display_th) : $display_th = false; ?>
<td class="font18" rowspan="<?php //echo esc_attr(count($shipping_methods)); ?>"><?php echo esc_html(sprintf(__('Shipping', 'woocommerce-subscriptions'), $shipping_method->label)); ?></td>
<?php else: ?>
<th class="font18"> </th>
<?php endif; ?>
<td class="font18 text-right fontbold">
<?php
if ($shipping_method->cost == 0) {
echo "Free";
} else {
echo wc_price($shipping_method->cost);
}
//echo wp_kses_post(wcs_cart_totals_shipping_method($shipping_method, $recurring_carts[$recurring_cart_key]));
?>
</td>
</tr>
<?php
//}
$ii++;
endforeach;
?>
<?php $display_th = true; ?>
<?php endif; ?>
<?php
$jj = 0;
foreach ($recurring_carts as $recurring_cart_key => $recurring_cart) :
//if ($jj == 0) {
?>
<?php
if (0 == $recurring_cart->next_payment_date) :
?>
<?php continue; ?>
<?php endif; ?>
<tr class="cart-subtotal recurring-total font18 hide<?php
echo $jj > 0 ? ' nobordertop' : '';
echo (count($recurring_carts) > 1 && $jj == 0) ? ' noborderbottom' : '';
?>">
<td class="desktop carthide"> </td>
<?php if ($display_th) : $display_th = false; ?>
<th class="text-uppercase" rowspan="<?php //echo esc_attr($carts_with_multiple_payments); ?>"><?php esc_html_e('Total per month', 'woocommerce-subscriptions'); ?></th>
<?php else: ?>
<th class="font18"> </th>
<?php endif; ?>
<!--<td><?php //wcs_cart_totals_subtotal_html($recurring_cart); ?></td>-->
<td class="text-right fontbold"><?php echo $recurring_cart->get_cart_subtotal(); ?></td>
</tr>
<?php
//}
$jj++;
endforeach;
if (count($recurring_carts) > 1) {
?>
<style type="text/css">
#order_reviews .shop_table {
padding-bottom: 135px;
}
</style>
<?php
}
$display_th = true;
?>
<?php foreach (WC()->cart->get_coupons() as $code => $coupon) : ?>
<?php foreach ($recurring_carts as $recurring_cart_key => $recurring_cart) : ?>
<?php if (0 == $recurring_cart->next_payment_date) : ?>
<?php continue; ?>
<?php endif; ?>
<?php foreach ($recurring_cart->get_coupons() as $recurring_code => $recurring_coupon) : ?>
<?php
if ($recurring_code !== $code) {
continue;
}
?>
<tr class="cart-discount coupon-<?php echo esc_attr($code); ?> recurring-total">
<?php
if ($display_th) : $display_th = false;
if (!session_id())
@session_start();
$session_coupon_code = isset($_SESSION['data_coupon']['coupon_code']) ? $_SESSION['data_coupon']['coupon_code'] : '';
?>
<th rowspan="<?php echo esc_attr($carts_with_multiple_payments); ?>">Gifd Card: <?php echo (in_array($code, array('firstreferee', 'firstreferee407', 'firstreferee408', 'firstreferee409')) || $code == strtolower($session_coupon_code)) ? '' : $code; ?></th>
<?php endif; ?>
<td><?php wcs_cart_totals_coupon_html($recurring_coupon, $recurring_cart); ?></td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
<?php $display_th = true; ?>
<?php endforeach; ?>
<?php if (WC()->cart->tax_display_cart === 'excl') : ?>
<?php if (get_option('woocommerce_tax_total_display') === 'itemized') : ?>
<?php foreach (WC()->cart->get_tax_totals() as $code => $tax) : ?>
<?php foreach ($recurring_carts as $recurring_cart_key => $recurring_cart) : ?>
<?php if (0 == $recurring_cart->next_payment_date) : ?>
<?php continue; ?>
<?php endif; ?>
<?php foreach ($recurring_cart->get_tax_totals() as $recurring_code => $recurring_tax) : ?>
<?php
if ($recurring_code !== $code) {
continue;
}
?>
<tr class="tax-rate tax-rate-<?php echo esc_attr(sanitize_title($code)); ?> recurring-total">
<?php if ($display_th) : $display_th = false; ?>
<th><?php echo esc_html($recurring_tax->label); ?></th>
<?php else : ?>
<th></th>
<?php endif; ?>
<td><?php echo wp_kses_post(wcs_cart_price_string($recurring_tax->formatted_amount, $recurring_cart)); ?></td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
<?php $display_th = true; ?>
<?php endforeach; ?>
<?php else : ?>
<?php foreach ($recurring_carts as $recurring_cart_key => $recurring_cart) : ?>
<?php if (0 == $recurring_cart->next_payment_date) : ?>
<?php continue; ?>
<?php endif; ?>
<tr class="tax-total recurring-total">
<?php if ($display_th) : $display_th = false; ?>
<th><?php echo esc_html(WC()->countries->tax_or_vat()); ?></th>
<?php else : ?>
<th></th>
<?php endif; ?>
<td><?php echo wp_kses_post(wcs_cart_price_string($recurring_cart->get_taxes_total(), $recurring_cart)); ?></td>
</tr>
<?php endforeach; ?>
<?php $display_th = true; ?>
<?php endif; ?>
<?php endif; ?>
<?php foreach ($recurring_carts as $recurring_cart_key => $recurring_cart) : ?>
<?php if (0 == $recurring_cart->next_payment_date) : continue; ?>
<?php endif; ?>
<tr class="order-total recurring-total">
<td class="desktop carthide"> </td>
<?php if ($display_th) : $display_th = false; ?>
<th class="text-uppercase" rowspan="<?php //echo esc_attr($carts_with_multiple_payments); ?>"><?php esc_html_e('Total per month', 'woocommerce-subscriptions'); ?></th>
<?php endif; ?>
<td class="text-right fontbold">
<?php // wcs_cart_totals_order_total_html($recurring_cart); ?>
<?php echo $recurring_cart->get_total(); ?>
</td>
</tr>
<?php endforeach; ?>
<script>
jQuery(document).ready(function ($) {
<?php if (!$isUpgrade) { ?>
$shippingwc = getAmountSubscription('.shippingwc .amount');
$total = getAmountSubscription('.product-total .amount');
$discount = getAmountSubscription('.cart-discount .amount');
if ($('.order-total .amount').length > 0) {
if ($('.cart-before-discount').length > 0) {
$('.cart-before-discount .amount').html('$' + ($total + $shippingwc).toFixed(2));
$('.order-total th').html('First Month Payment:');
}
$('.order-total .amount').html('$' + ($total - $discount + $shippingwc).toFixed(2));
}
<?php
}
?>
$('.amount').each(function () {
current_amount = $(this).html();
if (current_amount.indexOf('AUD') === -1 && current_amount.indexOf('$') !== -1) {
$(this).html($(this).html() + ' AUD');
}
});
<?php if (isset($shipping_country) && $shipping_country != '' && $shipping_country != 'AUD') { ?>
// if ($('.link_term_different_currency').length === 0) {
// $('input[name="woocommerce_checkout_place_order"]').closest('div').append('<br/><span class="link_term_different_currency">If you are paying in a different currency from AUD, <a href="#">Click Here</a> to read our Terms and Conditions</span>');
// }
// else {
// $('input[name="woocommerce_checkout_place_order"]').closest('div').find('.link_term_different_currency').remove();
// $('input[name="woocommerce_checkout_place_order"]').closest('div').find('br').remove();
// }
<?php } ?>
if ($('.cart-discount').length > 0) {
$('.add_gift_card').html('Gift Card? Code already applied.');
}
});
function getAmountSubscription(element_class) {
if (jQuery(element_class).length > 0) {
return parseFloat(jQuery(element_class).html().replace('$', '').replace('AUD', ''));
}
else {
return 0;
}
}
</script>