Skip to content

Commit 50e16a7

Browse files
author
ellynoize
committed
add error and js
1 parent 0bf0727 commit 50e16a7

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

src/include/class-wc-retailcrm-base.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public function __construct($retailcrm = false)
115115
add_action('shutdown', [$this, 'create_order'], -2);
116116
add_action('wp_console_upload', [$this, 'console_upload'], 99, 2);
117117
add_action('wp_footer', [$this, 'add_retailcrm_tracking_script'], 102);
118+
add_action('wp_footer', [$this, 'bonus_charge'], 103);
118119

119120
//Tracker
120121
add_action('wp_ajax_retailcrm_get_cart_items_for_tracker', [$this, 'get_cart_items_for_tracker'], 99);
@@ -1679,6 +1680,31 @@ public function add_retailcrm_tracking_script() {
16791680
}
16801681
}
16811682

1683+
public function bonus_charge()
1684+
{
1685+
?>
1686+
<script>
1687+
jQuery(document).ready(function($) {
1688+
$('.charge-button').on('click', function(e) {
1689+
let bonusCount = document.getElementById('chargeBonus').value;
1690+
let max = document.getElementById('hidden-count').textContent;
1691+
1692+
if (bonusCount > max) {
1693+
let error = document.getElementById('error');
1694+
error.innerText = "Больше допустимого";
1695+
error.hidden = false;
1696+
error.style.color = 'red';
1697+
1698+
return;
1699+
}
1700+
1701+
error.hidden = true;
1702+
});
1703+
});
1704+
</script>
1705+
<?php
1706+
}
1707+
16821708
private function accessLog($prefixNonce = ''): void
16831709
{
16841710
if ($prefixNonce !== '') {

src/include/class-wc-retailcrm-loyalty.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,24 +299,26 @@ public function createLoyaltyCoupon($refreshCoupon = false)
299299

300300
$html = sprintf(
301301
'<div style="margin-bottom:15px padding-top:15px">
302+
<div id="hidden-count" hidden>%d</div>
302303
<input type="number" id="chargeBonus" name="charge" value="0"/>
303-
<label style="%s" for="chargeBonus">%s</label>
304-
<button>Списать бонусы</button>
304+
<label for="chargeBonus">%s</label>
305+
<button type="button" class="charge-button">Списать бонусы</button>
306+
<div id="error" hidden></div>
305307
</div>',
306-
"",
308+
$lpDiscountSum / $lpChargeRate,
307309
esc_html__('Введите кол-во бонусов для списания', 'woo-retailcrm')
308310
);
309311

310312
$allowed_tags = [
311-
'div' => ['style' => []],
313+
'div' => ['style' => [], 'hidden' => [], 'id' => []],
312314
'input' => [
313315
'type' => [],
314316
'id' => [],
315317
'name' => [],
316318
'value' => [],
317319
],
318320
'label' => ['for' => [], 'style' => []],
319-
'button' => ['style' => []],
321+
'button' => ['style' => [], 'type' => [], 'class' => []],
320322
];
321323

322324
echo wp_kses($html, $allowed_tags);

0 commit comments

Comments
 (0)