How would I add an ID to my add to cart button on the product info page?
I am trying to install facebook tracking, but it requires the add to cart button to have an ID
How would I add an ID to my add to cart button on the product info page?
I am trying to install facebook tracking, but it requires the add to cart button to have an ID
Nick Smith - Venture Design and Print
https://venturedesignandprint.co.uk
Do they want the "button" itself to have an id? Or the form that it's submitting?
You said this is the product_info page, so the template file is tpl_product_info_display.php
If the form needs an ID, you can add it to the zen_draw_form call near the top of the template file:
or for the button itself, there are two places depending on the quantity limits of the product and whether it is already in the cart.Code:<?php echo zen_draw_form('cart_quantity', zen_href_link(zen_get_info_page($_GET['products_id']), zen_get_all_get_params(array('action')) . 'action=add_product', $request_type), 'post', 'enctype="multipart/form-data" id="myAddtoCartForm"') . "\n"; ?>
Both variants are in an if/else block in the middle of the file. Best to set the id on both:
Code:if ($products_qty_box_status == 0 or $products_quantity_order_max== 1) { // hide the quantity box and default to 1 $the_button = '<input type="hidden" name="cart_quantity" value="1" />' . zen_draw_hidden_field('products_id', (int)$_GET['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT, ' id="myAddToCartButton"'); } else { // show the quantity box $the_button = '<div class="max-qty">' . zen_get_products_quantity_min_units_display((int)$_GET['products_id']) . '</div><span class="qty-text">' . PRODUCTS_ORDER_QTY_TEXT . '</span><input type="text" name="cart_quantity" value="' . $products_get_buy_now_qty . '" maxlength="6" size="4" />' . zen_draw_hidden_field('products_id', (int)$_GET['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT, ' id="myAddToCartButton"'); }
.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole
Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.
It needs to be an ID on the actual button. This is the facebook code example to give you a better idea:
HTML Code:<button id="addToCartButton">Purchase</button><script type="text/javascript"> $('#$addToCartButton').click(function() { fbq('track', 'Purchase', {currency: "USD", value: 30.00}); });</script>
Nick Smith - Venture Design and Print
https://venturedesignandprint.co.uk
where would I add this bit though?
HTML Code:<script type="text/javascript"> $('#$addToCartButton').click(function() { fbq('track', 'Purchase', {currency: "GBP"}); });</script>
Nick Smith - Venture Design and Print
https://venturedesignandprint.co.uk
If it's something specific to just that page then you can just put it in the bottom of that template file.
Technically just needs to appear after the element with that ID is output, and since it's expecting jQuery, anywhere after jQuery is initialized (which is probably already done in the template header).
The "#$addToCartButton" bit needs to be named according to whatever ID you called it ... and get rid of the $ after the #. Not sure why that was there.
.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole
Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.
Nick Smith - Venture Design and Print
https://venturedesignandprint.co.uk
Bookmarks