Behseini
Behseini

Reputation: 6320

Need some hints for my own WP Theme

After taking some online tutorials I am willing to create my own custom theme for my myself. This is going to be an online Contact Lense store! So far I have learned how to generate and use Custom Post Types, Custom Taxonamyies, Metaboxes , and Option pages.but there is still one confusing part left for me(hopefully not more! :-))
I need to get some user inputs through HTML Select Options like following image to finalize the users orders: enter image description here

Now my question is:
1- Do I have to create some thing lik Metaboxes to manipulate these data from users?
2- can I handle these kind of data through simple Form ans Post function in PHP? If so where should I store these data? Do I have to create a table on my own to handle these things?
I really appreciate your time regrading this post,

Upvotes: 0

Views: 94

Answers (1)

maiorano84
maiorano84

Reputation: 11951

What you're asking for carries a little more complexity than you think!

Let's break this down into its meaningful steps:

  1. A user visits your shop, and decides that they like what they see and wants to make an order
  2. The user fills out a form defining their exact eye requirements, quantity, as well as their contact information
  3. Upon completing this form, a new order has been created

But wait.... how will you get paid? What happens if the user's computer explodes before the payment goes through? How will you know to send them their contacts without first knowing the payment even succeeded?

This is where things start to get tricky. You need to be able to keep a record of orders for the sake of your users, but you also need to look out for your own interests too. Your business is doomed to fail if you're sending out expensive products to people without the proper assurance that you're getting paid.

This is where you'll need to set up a Merchant Account with a service like PayPal or Google Checkout. As much as I despise PayPal, their Instant Payment Notification (IPN) System has been very reliable for me. What this does is automatically send a POST request to your server with all of the information you need to finalize the checkout process and alert your user that their payment has either succeeded or failed.

So with this in mind, how does this affect our step-by-step process?

  1. A user visits your shop, and decides that they like what they see and wants to make an order
  2. The user fills out a form defining their exact eye requirements, quantity, as well as their contact information
  3. Upon completing this form, a new order has been created with a status of pending
  4. The user is then sent to PayPal/Google Checkout to enter their Credit Card information to complete their purchase
  5. PayPal/Google processes the payment
  6. PayPal/Google sends your server the results of the processed payment
  7. The corresponding order is updated with a status of Payment Received or Payment Failed for your own records
  8. You send out the product to a very satisfied customer

So what will this mean from a Wordpress standpoint?

My first suggestion:

Check if a Plugin already exists that can handle this for you!!!

Seriously, this will make your life much easier. Handling people's money as well as your own stock is a nightmare all in itself, you don't want to be responsible for handling the code that drives it, or the possibility of security holes that you might not know about (that other plugins may have already addressed). WooCommerce is a popular one. See if that can handle what you need.

If a Plugin can't do it for you, then you'll need to:

  • Register a Custom Post Type for Orders
  • Create a new Order Post using wp_insert_post when a user submits the form with their POST data
  • Save the relevant POST data you need as metadata using update_post_meta
  • Send PayPal/Google/Whatever some Custom Information it needs to hang on to - in this case, the newly created Order Post ID - so that it can send it back to your own server
  • Set up a side-script to process the data sent by PayPal/Google Checkout/Whatever and send an email to the user detailing the status of their purchase and update the corresponding Order Post ID that was sent back by PayPal/Google Checkout/Whatever
  • (Optional) Set up a CRON Job to periodically scan all Pending orders in case a user's session was interrupted, or they bailed at the last second during checkout and send them an email notifying them about this and provide them a link to your website to reopen, reevaluate, and resend the order, or cancel and clear it from your database

Quite honestly, this would take even a seasoned Developer at least a few weeks worth of work just to get it in working condition. Presentation is a whole different animal.

Hopefully this will give you a step in the right direction. I doubt anybody here will give you the code to do what you need, because there's just too much to post. Entire libraries are built just for these kinds of things.

Good luck!

Upvotes: 1

Related Questions