Sina Saeedi
Sina Saeedi

Reputation: 45

Store shopping cart items on cookie or DB on customized wordpress ecommerce plugin

I'm writing a new customized e-commerce plugin. I want to publish it on WordPress plugins directory too. I've created a new custom post type for "Products" as long as a new CPT for "Orders". I have a "Shop Settings" page that contains some options too. I'v also created shortcodes to use in "Cart" and "Checkout" pages.

Now I'm in the middle of codding for "Add to Cart" section. I have a question, could you please help me? For processing Cart contents, I have three solutions:

  1. Keep Cart contents in Cookie Keep Cart contents in Session Keep Cart contents in DB
  2. Cookies are fast and they doesn't have any load on server. But they are not secure and will be deleted after a period of time.
  3. Sessions have not implemented in WordPress (so far I know)
  4. DB is a good solution and permanent, but It needs so many DB transactions that causes junk data on DB and load on server.

Do you have a solution or help for me? If your answer is to choose DB solution, what about to define Cart as a CPT and keeping it's contents as meta?

Upvotes: 2

Views: 1507

Answers (1)

Maha Dev
Maha Dev

Reputation: 3965

Database : By using the DB method, you will save the cart against a particular user id, but what about the users who are not logged in.

Session : By using sessions, cart will be empty after browser closed.

Cookie + Session : In my point of view, you need to use session+cookies. Save data in cookie and populate that data into session for further use. Also by using cookie, it will remain persists after the browser closed.

Upvotes: 2

Related Questions