• I’m working with a site where I need to have a user add/update/remove items from a cart similar to WooCommerce however we aren’t using WooCommerce and don’t plan on doing so. I need to be able to have each user manage a cart and then be able to checkout, (again very similar to what WooCommerce is doing), which involves them entering in checkout fields without payment. The form will build and send an email off along with some other custom processing to hit an external API. What’s the best way to manage this without using WooCommerce? I’ve read about WordPress session tokens in the docs, but I can’t seem to find any examples that would help me get off the ground. Any help is greatly appreciated!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator bcworkz

    (@bcworkz)

    I can think of 4 ways to have data persist between requests. It’s debatable which is best, they all have pros and cons. Session vars is one. People seem to have trouble implementing sessions properly, but in theory it’s a good option. You could save persistent data in cookies. Tried and true, but have privacy implications, especially if you’re subject to GDPR requirements. Data can be passed via an URL query string. Limited application. Data could be saved as transients, but this requires the user to be logged in so they can be identified. Identity is managed via a cookie.

    Thread Starter philipatnedi

    (@philipatnedi)

    I think the best route would be to use some sort of session variables, but from what I’ve read I shouldn’t use PHP session states directly and instead try to leverage WordPress. My issue is that I haven’t found any examples or use cases that can get me started. I’m basically trying to replicate WooCommerce’s cart and checkout except there won’t be payment processing.

    Moderator bcworkz

    (@bcworkz)

    I think WooCommerce uses all 4 of the methods I mentioned. I haven’t seen how they use sessions, but they leave a cookie with a session ID, so I assume sessions are used. They probably do not pass personal details as URL query strings, but query strings are certainly used. Cookies and transients are definitely used as well.

    Thread Starter philipatnedi

    (@philipatnedi)

    That sounds great, I’m looking for examples or use cases that can help me set up a cart/checkout that is similar to what WooCommerce is currently doing. We don’t want to use WooCommerce as we are pulling in the products via a third party API call and they aren’t stored on the WordPress site-side of things.

    I wonder if it’s possible to get WooCommerce up and running without products and use meta fields to override the product details. That way we wouldn’t have to rebuild the cart/checkout from scratch?

    Moderator bcworkz

    (@bcworkz)

    The WC cart is tightly integrated to products. I think it’d be hard to separate the two without also breaking its functionality. That said, products are just a custom post type, a generic data container if you will. It’s called “product”, but it doesn’t have to be a literal product, it’s just a data type collected in a user’s cart. The product’s meta data could contain any sort of data you want.

    The cart itself is very customizable. It’s template can be altered as desired, but it’s usually not necessary because it’s all driven by action hooks. By adding or removing hook callbacks you can alter its appearance and function in all sorts of ways.

    If nothing else, examine the WC source code as guidance in developing your own cart solution.

    Thread Starter philipatnedi

    (@philipatnedi)

    Yes I’ve found a few solutions to where a single product is set up as a generic product and then when it gets added to cart the price/name/other product details are overridden with other values set via hidden fields.

    I’d like to learn more about how WooCommerce handles it’s cart via session and cookies but I’m having no luck finding any examples or use cases to build off of.

    At this point I just want to find a solution, so I’m going to try to set up a generic product and override the values.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘WordPress sessions’ is closed to new replies.