I am currently working on a WordPress project where I have a wed store made up using WooCommerce, and as a practice project I've decided to make refund system for customers to use, where they can send a "Refund request" for the site admins to either accept or deny.
The refund tab is split into 3 different pages where on the first page the customer confirms his/her order by inputting her Name, PostCode and the order number, on the second page the customer can choose the products they want to order and their quantity by inputting the number, and checking the product's checkbox and the third page is just a confirmation page where the customer can also send a message and then they press the "Send request button". And after the button is pressed the information from the request tab is inserted to a custom table called wp_refundrequests, which is used to show all the requests on the admin page.
My problem is that on the second page, where the customer is supposed to select to amount of certain products they want a refund for, always shows the maximum amount in my code, and I can't wrap my head around on how to make it work so, that it would only take the user inputted amount.
Here is the code for the second page, where the problem is:
<div class="Etusivu">
<form action="" method="post" style="border:0px solid #ccc">
<legend><b>Product refund</b></legend>
<div class="step">
<legend>Step 2/3</legend>
</div>
<br />
<p class="important">Order information</p>
<br />
<div class="valitse">
<p class="important">Choose all of the products you want to refund.</p>
</div>
<hr>
<script>
//function for making a checkbox to check all checkboxes
function toggle(source) {
checkboxes = document.getElementsByName('productinfo[]');
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
}
}
</script>
<input type='checkbox' onClick='toggle(this)' />
<p class="selectall">Select all products</p>
<label>The order:</p>
<br />
<?php
//Gets and displays data based on certain variables from the database, connects quantity and product name into one string in
$order = wc_get_order( $ordernumber );
foreach ($order->get_items() as $item ){
$unitprice = $item->get_total() / $item->get_quantity();
// This is the part that currently gets the quantity value for the next page/the refund request
echo "<input type='checkbox' name='productinfo[]' value='" . " " . $item->get_name() . " , " . $item->get_quantity() . " QTY" . " | " . $item->get_total() ."'>";
echo '<p>';
echo __('Product name: ' ) . $item->get_name() . '<br>';
if($item->get_quantity() > 1) {
echo "Quantity: " . "<input type='number' name='numberqty' value='" . $item->get_quantity() . "'max='" .$item->get_quantity() . "' min='1' > " . "<br/>";
}
else {
echo __('Quantity: ' ) . $item->get_quantity() . '<br>';
}
if ($item->get_quantity() > 1) {
echo __('Product price: ') . $unitprice . '€' . '<br/>';
}
echo __('Products total: ' ) . wc_price($item->get_total()) . '</p>' . '<br/>';
}
echo '<p>'. __('Order total: ') . $order->get_total() . '</p>';
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="submit" id='check' value="Next"/>
<script>
//Checks if any checkboxes have been checked, if not, displays an error
function checkBoxCheck() {
if($('input[name="productinfo[]"]:checked').length) {
console.log("at least one checked");
return true;
}
else {
alert("Select at least 1 product.");
return false;
}
}
//runs the script for checking the checkboxes
$('#check').on('click', checkBoxCheck);
</script>
</label>
<input type="hidden" name="page" value="2">
</form>
<br />
</div>
</body>
</html>
<?php
If there is anything that confuses you, please tell and I'll edit and try to answer you as fast as possible! Thank you in advance
from Change or update checkbox values using user inputs
No comments:
Post a Comment