I'm currently working on a plugin that uses image buttons to add a predefined message to the order.
What I would like to do however is assign a price to each of the buttons, which also gets added to the order. Kind of like a custom option assigned to each button, but something I can code in myself.
Is this possible? I can't find any info to adjust the price of the cart using buttons/code.
Any suggestion greatly appreciated.
It's simple javascript, unless you want to do it server side, which would be easy but require mysql.
HTML CODE:
<img src="" onclick="item_1()"> //just add the src (path) and some style.
<img src="" onclick="item_2()"> //if you need a third just repeat the same and change the numbers.
<p id="total_order">$0</p> //that's the paragraph that shows the total bill (can be a div too)
JAVASCRIPT:
var order = 0;
var price_1 = "price"; //simply change "price" for the price you want
var price_2 = "price";
function item_1() {
order += price_1; //increments the order value by the price of the 1st item
document.getElementById("total_order").innerHTML = "$"+order;
}
//same function repeated but with different number
function item_2() {
order += price_2;
document.getElementById("total_order").innerHTML = "$"+order;
}
I don't know if that's what you're looking for, but I hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.