如何显示变量WooCommerce产品的价格?

时间:2017-05-18 15:59:49

标签: javascript wordpress woocommerce

我想显示变量WooCommerce产品的价格(稍后在销售价格旁边的正常价格)。代码被插入到我的登录页面上的块(类似于小部件)中。不幸的是我的价格div没有工作/显示任何东西:(

你能帮帮我吗?

提前致谢!

<div id="variant">
    <label><input type="radio" name="toggle" id="3"><span>3 Natural Energy-Riegel</span></label>
    <label><input type="radio" name="toggle" id="12" checked="checked"><span>12 Natural Energy-Riegel</span></label>
    <label><input type="radio" name="toggle" id="24"><span>24 Natural Energy-Riegel</span></label>
</div>

<div id="price"></div>

<script type="text/javascript">
function get_product_price() {

var $radio = $('input[name=toggle]:checked');

    if ($radio.attr("id") == 3) {
        $_product = wc_get_product('297');
        $price = $_product->get_price();
    } elseif ($radio.attr("id") == 12) {
        $_product = wc_get_product('299');
        $price = $_product->get_price();
    } else ($radio.attr("id") == 24) {
        $_product = wc_get_product('300');
        $price = $_product->get_price();
    }

document.getElementById('price').innerHTML = $price;

}
</script>

0 个答案:

没有答案