0
我需要动态获取用户选择的任何选项的值,并将该值返回到按钮单击时的Facebook Pixel。需要从表单中选择选项值并通过jquery/javascript传回
请参阅选择的选项值在脚本区域。
<form action="/cart/add" method="post" enctype="multipart/form-data" class="AddToBagForm text-center medium-up--text-left" novalidate>
<select name="id" id="product-select-2585865157" class="product-single__variants">
<option selected="selected" value="7534116741">White Marble/S - $39.95 USD</option>
<option value="7534116869">White Marble/L - $39.95 USD</option>
<option value="7534117061">Midnight/S - $39.95 USD</option>
<option value="7534117253">Midnight/L - $39.95 USD</option>
<option value="9032311493">Maroon/M - $39.95 USD</option>
<option value="9032318853">Maroon/L - $39.95 USD</option>
</select>
<div class="add-container clearfix">
<a href="#" class="btn--primary BIS_trigger" data-product-handle="mighty-ganesh-flowy-top" data-variant-id="7534116741">Get Notified</a>
<div class="quantity-field">
<label for="Quantity" class="quantity-selector">Qty:</label>
<input type="number" id="Quantity" name="quantity" value="1" min="1" max="3" class="quantity-selector">
</div>
<button type="submit" name="add" class="AddToBag btn--primary" id="add-to-cart" >
<span class="AddToBagText">Add to Bag</span>
</button>
</div>
<script type="text/javascript">
$('#add-to-cart').click(function() {
fbq('track', 'AddToCart', {
content_ids: '{{ product.id }}.' + **SELECTED OPTION VALUE**,
content_type: 'product',
value: {{ product.price | money_without_currency}},
});
});
</script>
</form>
感谢。我会尽快检查。一个快速后续问题:产品选择 - #是动态的,使用Shopify的内部变量之一:
我的答案已更新,以获取select类的值(请参阅注释代码)。 –
太棒了@Jeff!它像一个魅力。 – JoeyM