This function was deprecated
Original quastion :
For all kinds of suggest and helps with much appreciated.
I was trying build a function let the selected product which in the Cart
move to another table so there I can reorder them each fitting to the customer demanded.
and my biggest problem is that I don't have clue how to deal with this situation when I can't trans them into array, omg
when the products put in Cart would be like:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<tbody class="table-border" id="My_OrderCart_tbody">
<tr>
<div class="row-fluid gx-2 px-2">
<dl data-place_id="dl7557">
<dd class="px-1">J. De Telmont Grand Reserve Brut NV Champagne (15Litre)</dd>
</dl>
</div>
<div class="px-2"><input class="input form-control" type="number" id="Quan7557" value="1" data-id="7557">
</div>
<div class="mx-auto"><span>$</span>
<input type="text" class="input form-control" id="Price7557" data-id="7557" value="10500">
</div>
<div class="row max-auto px-3">
<input type="button" class="btn btn-sm Remove" id="7557" value="Remove"></div>
</tr>
<tr>
<span>SubTotoal :</span><span>$</span>
<input type="text" class="input form-control" id="Sub_7557" value="10500.00" disabled="">
</tr>
<tr>
<div class="row-fluid gx-2 px-2">
<dl data-place_id="dl7556">
<dd class="px-1">Taittinger Reserve Vintage Brut Champagne</dd>
</dl>
</div>
<div class="px-2"><input class="input form-control" type="number" id="new_Quan7556" value="1" data-id="7556">
</div>
<div class="mb-2 mx-auto">
<span>$</span><input type="text" class="input form-control" id="Price7556" data-id="7556" value="486">
</div>
<div class="row"><input type="button" class="btn Remove" id="7556" value="Remove">
</div>
</tr>
<tr>
<span>SubTotoal :</span><span>$</span>
<input type="text" class="input form-control fst-italic mbi-sub-text sub_total" id="new_Sub_a_7556" value="486.00" disabled="">
</tr>
<tr>
<div class="align-center">
<span class="text">Grand Total:</span>
<input type="text" id="gTotal1" value="10986" hidden="">
<span class="text" id="Grand_Total1" align="right">$ 10,986.00 </span>
</div>
</tr>
as the code shows the product all got different data-ids like:
<dl class="list-group list-unstyled" data-place_id="dl7557">
<dl class="list-group list-unstyled" data-place_id="dl7556">
I was trying to get the data-Id since the rest of calculate such as Quantity
, Price
also control by same date-Id
<script>
$(document).on('click', '#saveBtn, #view-table', function() {
$('#My_OrderCart_tbody tbody tr').each(function() {
var data_id = $(this).find("dl[id^=dl]").data("place_id");
});
console.log(data_id);
});
</script>
but the script doesn't work which says: Uncaught ReferenceError: data_id is not defined
I was thinking putting the values while users altered into other elements.
following function would be send altered values ajax post
add to the Cart-table:
<script>
$(document).ready(function(data){
$('.add_to_cart').click(function(){
var product_id = $(this).attr("id");
var product_name = $('#name'+product_id).val();
var product_price = $('#price'+product_id).val();
var product_quantity = $('#quantity'+product_id).val();
var action = "add";
if (product_quantity > 0){
$.ajax({
url:"action.php",
method:"POST",
dataType:"json",
data:{
product_id:product_id,
product_name:product_name,
product_price:product_price,
product_quantity:product_quantity,
action:action
},
success:function(data){
$('#order_table').html(data.order_table);
$('.badge').text(data.cart_item);
alert("Product has been Added into Cart");
}
});
} else {
alert("Please Enter Number of Quantity")
}
});
</script>
For the PHP site using $_SESSION and $_POST to handle the values such as pass-javascript-variable-to-php-and-then-to-cart-and-order-line-items-in-woo-com
If it could possible getting the data-Id of each dl
then IMPO it is very likely could've solve by origin code $('prefix' + ids).val(); or .text();
even thought I found some answers like change ids into class, but I still need ids to control the calculate part
get-multiple-id-at-once-at-set-a-function
display-results-of-event-on-multiple-id
Thank you for reading here, LOL