Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2008
    Location
    Cleethorpes
    Posts
    1,227
    Plugin Contributions
    6

    red flag ID on Add To Cart button

    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

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: ID on Add To Cart button

    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:
    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"; ?>
    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.
    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.

  3. #3
    Join Date
    Sep 2008
    Location
    Cleethorpes
    Posts
    1,227
    Plugin Contributions
    6

    Default Re: ID on Add To Cart button

    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

  4. #4
    Join Date
    Sep 2008
    Location
    Cleethorpes
    Posts
    1,227
    Plugin Contributions
    6

    Default Re: ID on Add To Cart button

    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

  5. #5
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: ID on Add To Cart button

    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.

  6. #6
    Join Date
    Sep 2008
    Location
    Cleethorpes
    Posts
    1,227
    Plugin Contributions
    6

    Default Re: ID on Add To Cart button

    Quote Originally Posted by DrByte View Post
    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.
    Ok cool, I thought that was the case
    Nick Smith - Venture Design and Print
    https://venturedesignandprint.co.uk

 

 

Similar Threads

  1. v151 How do I replace the add-to-cart button with a PayPal *Donate* button?
    By picandnix in forum Addon Payment Modules
    Replies: 7
    Last Post: 29 Apr 2014, 02:52 PM
  2. v151 Add To Cart displaying alt text instead of add to cart button
    By AquaticAddiction in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 8 Feb 2014, 07:58 PM
  3. Help! Add to Cart button doesn't Add to Cart
    By WWRepair in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 7 Feb 2013, 07:42 AM
  4. Change the Add to Cart button to Buy Now button
    By dastudio in forum Customization from the Admin
    Replies: 1
    Last Post: 24 Nov 2010, 09:44 PM
  5. How do I replace the Buy Now button with an Add to Cart button?
    By OrcaSoul in forum Templates, Stylesheets, Page Layout
    Replies: 9
    Last Post: 19 Feb 2010, 05:36 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR