Dynamically Adding an Add To Cart Button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • FifthCloud
    Junior Member
    • Oct 2017
    • 7

    #1

    Dynamically Adding an Add To Cart Button

    I am having some trouble dynamically adding an Add To Cart button that I was wondering if anyone has ever tried this.

    Due to the large inventory of products I have I fetch more details from the server about the item the user has requested to see more info about. Below is a snippet of code that I am return to the client in order for them to add this item to cart.

    PHP Code:
    $easyCart = "<form action="https://example.com/cart/" method="POST" enctype="multipart/form-data" class="ec_add_to_cart_form">
        <input type="hidden" name="ec_cart_form_action" value="add_to_cart_v3">
        <input type="hidden" name="product_id" value="11">
        <div class="ec_details_add_to_cart_area">
            <div class="ec_details_add_to_cart">
                <input type="submit" value="ADD TO CART" onclick="return ec_details_add_to_cart_2( );">
            </div>
        </div>
    </form>" 
    
    The item exists within the database, but this doesn't add anything. I have copied this HTML code from the DEMO Store page by right clicking the Add To Cart and seeing how it has been done by that. Obviously, I am getting errors because things are missing.

    I am wondering what is most important information that I need to pass to the client? Can someone help me setup my form?

    If you need me to clarify anything or show more code please don't hesitate to ask.

    Thank you.
  • FifthCloud
    Junior Member
    • Oct 2017
    • 7

    #2
    Anyone have any ideas?

    Comment

    • admin
      Administrator
      • Feb 2013
      • 59
      • ***************************
        Josh Jones
        Level Four Development, llc
        ***************************

      #3
      I would suggest creating a blank new wordpress page, then use our shortcode 'add to cart' button and then look at the code it produces in a form...
      How do I add EasyCart shortcodes to a page? Click the cart icon in your editor toolbar, pick a shortcode, and drop it in — no code required.


      might help give you an idea of what needs to be there, just use the entire form on there and see if it works.

      Comment

      • FifthCloud
        Junior Member
        • Oct 2017
        • 7

        #4
        Thank you for your suggestion. I ended up just copying all the data of the form post and just renaming the product_id with the values of my product. Was able to get the results I wanted.

        Thanks!

        Comment

        Working...