0

I currently have a Wordpress Multisite set up with WooCommerce. My goal is to have a shared shopping cart in a GUEST session for a subbblog mapped domain, and full domain itself.

ie the shopping cart would be the same for:

While I can get the carts working independently, they will have their own cookies on each respective domain.

3 cookies manage the shopping cart experience:

  • woocommerce_items_in_cart
  • woocommerce_cart_hash
  • wp_woocommerce_session_

(Where wp_woocommerce_session_ will be something like this in practice:)

  • wp_woocommerce_session_e235b4c0280f7763c7ffd1dd8492f8a2

(ref: https://docs.woothemes.com/document/woocommerce-cookies/)

I modified the function wc_setcookie in the file: includes/wc-core-functions.php to set the cookies for both domains|paths with the following:

A normal cookie is set in this function via:

  • setcookie( $name, $value, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure );

I will add an additional cookie (for each cookie set with:

  • $temp1 = get_blog_details();
  • setcookie( $name, $value, $expire, $temp1->path, $temp1->domain, $secure );

However these secondary cookies are not seen when going to the other domain path.

So the question is how can I accomplish execute this via extra coding or server modifications in NGINX or with both.

Thank you for your time

bmiskie
  • 617
  • 8
  • 22

1 Answers1

0

Thankfully for privacy and security, you can't just set a cookie for a different domain due to same-origin policies implemented in browsers.

See the related Cross-Domain Cookies post on StackOverflow for a discussion of options when you control both domains.

The post Cross-domain-cookies - a maybe new idea explains another approach when you control both domains.

Community
  • 1
  • 1
Mark Stosberg
  • 12,961
  • 6
  • 44
  • 49
  • Hey mark, thanks for the response. Correct you can't simply just set a cookie. The question for guidence would be how to use javascript to complete the action or how to set up the server for this request or both....any ideas? – bmiskie Jan 25 '16 at 17:17
  • @bmiskie, JavaScript is thankfully also subject to same-origin policies. The linked ticket is going to have the best ideas for you, as your question is essentially a dupe of that. – Mark Stosberg Jan 25 '16 at 17:28
  • I've gone through these threads, also checked out a few links, just having trouble connecting the dots in the wordpress environment – bmiskie Jan 25 '16 at 18:12
  • Any answers specific to woo-commerce and 2 domains on the same server would be appreciated. – bmiskie Jan 25 '16 at 18:32