我目前正在开发一个插件,该插件使用图像按钮向订单添加预定义消息。
但是,我想做的是为每个按钮分配一个价格,该价格也会添加到订单中。有点像分配给每个按钮的自定义选项,但我可以自己编写代码。
这可能吗?我找不到任何使用按钮/代码调整购物车价格的信息。
非常感谢任何建议。
最佳答案
这是简单的 javascript,除非你想在服务器端进行,这很容易,但需要 mysql。
HTML 代码:
<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;
}
我不知道这是否是您要找的内容,但希望对您有所帮助。
关于javascript - 单击图像按钮会增加购物车价格 - Magento,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32260085/