• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Need Help Understanding HOW This PHP/jQuery Script Works (Not WHAT It Does)

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using the attached script, which is PHP and jQuery (with some AJAX mixed in for good measure), and is used in connection with WordPress/Woocommerce to add a checkout field to the checkout form that, when checked, will add the associated product to the customer's current order, using the product's ID.

I would like to understand better how this script works. That is, I would like each function explained in layman's terms, because I would like to modify to the script to work with multiple checkboxes and multiple products. (For the record: I made the mistake of heading over to Stack Overflow, forgetting how ego-maniacal and rude most of them are over there. Yikes! I've always had much more pleasant experiences here on the ranch. So, thanks y'all!)  



 
Adam Wentz
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess it might be helpful to share what I already know about this script.


Let's start with this function, the first one in the script:



This function, which I modified a bit from the original code, echos a div (that I've applied custom styling to). Within that div it places a headline, some paragraph text (the "content"), and then adds a checkbox field with a label. The checkbox field is added from an array that contains all the necessary information about it. Oh yeah, and the tells WordPress where the function should be hooked in at. In this case, it uses a Woocommerce hook to place the div and all its related content on the checkout form in the hook area BEFORE the area where the order notes field appears (if it's enabled).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic