| 1 |
<?php defined('ABSPATH') or exit; ?> |
| 2 |
$('.single_add_to_cart_button').on('click', function() { |
| 3 |
window.VWO = window.VWO || []; |
| 4 |
VWO.event = VWO.event || function() { |
| 5 |
VWO.push(["event"].concat([].slice.call(arguments))); |
| 6 |
}; |
| 7 |
var productSku = '<?php echo $productSku ?>'; |
| 8 |
var productTitle = '<?php echo $productTitle ?>'; |
| 9 |
var price = <?php echo $price ?> ; |
| 10 |
var productId = '<?php echo $productId ?>'; |
| 11 |
var productCategory = '<?php echo json_encode($productCategory) ?>'; |
| 12 |
var productUrl = '<?php echo $productUrl?>'; |
| 13 |
|
| 14 |
if ($('input[name="variation_id"]').val()) { |
| 15 |
var variant = $('input[name="variation_id"]').val(); |
| 16 |
|
| 17 |
$.each($('.variations_form').data('product_variations'), function(index, product) { |
| 18 |
if (product.variation_id == variant) { |
| 19 |
if (product.hasOwnProperty('sku')) { |
| 20 |
productSku = product.sku; |
| 21 |
} |
| 22 |
if (product.hasOwnProperty('display_price')) { |
| 23 |
price = product.display_price; |
| 24 |
} |
| 25 |
if (product.hasOwnProperty('attributes')) { |
| 26 |
productTitle += ' - '; |
| 27 |
var attributes = Object.values(product.attributes).join(', '); |
| 28 |
productTitle += attributes; |
| 29 |
} |
| 30 |
} |
| 31 |
}); |
| 32 |
} |
| 33 |
|
| 34 |
VWO.event("woocommerce.productAddedToCart", { |
| 35 |
"productTitle": productTitle, |
| 36 |
"productId": productId, |
| 37 |
"quantity": $('input.qty').val() ? parseInt($('input.qty').val()) : 1, |
| 38 |
"price": price, |
| 39 |
"productCategory": productCategory, |
| 40 |
"productUrl": productUrl, |
| 41 |
"variantId": productSku, |
| 42 |
"productSku": productSku |
| 43 |
}); |
| 44 |
}); |
| 45 |
|