WordPress/WC session not carried to next page
up vote
-1
down vote
favorite
Simply trying to store and retrieve unregistered customer data from page to page in a custom checkout template. I've stripped it down to the bare bones to try to pinpoint the issue.
This
<?php
$customer = WC()->customer;
$customer->set_billing_first_name("WORKING!!!");
$customer->save();
var_dump($customer->get_billing());
?>
Outputs this
array (size=2)
'country' => string 'US' (length=2)
'first_name' => string 'WORKING!!!' (length=10)
But then this
<?php
$customer = WC()->customer;
//$customer->set_billing_first_name("WORKING!!!");
//$customer->save();
var_dump($customer->get_billing());
?>
Outputs this
array (size=1)
'country' => string 'US' (length=2)
Even though I should still be firmly within the same session, and therefore should get the data stored before the comments. All I did was refresh the page after commenting out those two lines.
Am I completely wrong about these methods?
Checked
Environment is configured entirely correctly. Even had someone else double-check it for me. URLs, caches, etc.
It does appear to work when logged in, but the vast majority of users never do so that's not very helpful.
Have tried this on two different servers (one local, one remote) and have the same issue.
Started fresh with a new WP+WC install, created a blank theme, functions.php that does the above on init code. Same exact issue.
php wordpress session woocommerce
add a comment |
up vote
-1
down vote
favorite
Simply trying to store and retrieve unregistered customer data from page to page in a custom checkout template. I've stripped it down to the bare bones to try to pinpoint the issue.
This
<?php
$customer = WC()->customer;
$customer->set_billing_first_name("WORKING!!!");
$customer->save();
var_dump($customer->get_billing());
?>
Outputs this
array (size=2)
'country' => string 'US' (length=2)
'first_name' => string 'WORKING!!!' (length=10)
But then this
<?php
$customer = WC()->customer;
//$customer->set_billing_first_name("WORKING!!!");
//$customer->save();
var_dump($customer->get_billing());
?>
Outputs this
array (size=1)
'country' => string 'US' (length=2)
Even though I should still be firmly within the same session, and therefore should get the data stored before the comments. All I did was refresh the page after commenting out those two lines.
Am I completely wrong about these methods?
Checked
Environment is configured entirely correctly. Even had someone else double-check it for me. URLs, caches, etc.
It does appear to work when logged in, but the vast majority of users never do so that's not very helpful.
Have tried this on two different servers (one local, one remote) and have the same issue.
Started fresh with a new WP+WC install, created a blank theme, functions.php that does the above on init code. Same exact issue.
php wordpress session woocommerce
1
That is a normal thing if$customer->get_id()
is0
which happens when you're not logged-in. WooCommerce stores the session identifier (the user ID or an auto-generated customer ID) in the browser's cookies, and not the superglobal$_SESSION
. Tryvar_dump( $customer->get_billing(), $customer->get_id(), WC->session->get_customer_id() )
and see the output when you're logged-in and not.
– Sally CJ
Nov 11 at 23:55
@SallyCJ ah okay so my root assumption that this stores customer data in a session is false? I am seeing thewp_woocommerce_session_xxx=yyyy
cookie passed up in the request... it there a built-in way to store this customer data temporarily?
– Randy Hall
Nov 12 at 0:02
1
Your assumption is basically true; however, the session data (other than the session identifier; e.g. cart contents) are stored in{prefix}woocommerce_sessions
table - e.g.wp_woocommerce_sessions
. And this is same to how the WordPress authentication works, where your user ID is saved in the cookie, but the rest of your session are saved in the database. You can useWC()->session->set()
to save data temporarily, which can persist across pages - but of course cookies must be enabled in the user's browser.
– Sally CJ
Nov 12 at 0:19
@SallyCJ I'm seeing the same issue, usingWC()->session
, setting a var, then commenting out the set and refreshing the page. The value I saved and successfully returned usingWC()->session->set()
andWC()->session->get()
is just flat out not there after navigation.
– Randy Hall
Nov 12 at 8:27
1
Check my answer and let me know how it goes. Hopefully it works..
– Sally CJ
Nov 12 at 10:29
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
Simply trying to store and retrieve unregistered customer data from page to page in a custom checkout template. I've stripped it down to the bare bones to try to pinpoint the issue.
This
<?php
$customer = WC()->customer;
$customer->set_billing_first_name("WORKING!!!");
$customer->save();
var_dump($customer->get_billing());
?>
Outputs this
array (size=2)
'country' => string 'US' (length=2)
'first_name' => string 'WORKING!!!' (length=10)
But then this
<?php
$customer = WC()->customer;
//$customer->set_billing_first_name("WORKING!!!");
//$customer->save();
var_dump($customer->get_billing());
?>
Outputs this
array (size=1)
'country' => string 'US' (length=2)
Even though I should still be firmly within the same session, and therefore should get the data stored before the comments. All I did was refresh the page after commenting out those two lines.
Am I completely wrong about these methods?
Checked
Environment is configured entirely correctly. Even had someone else double-check it for me. URLs, caches, etc.
It does appear to work when logged in, but the vast majority of users never do so that's not very helpful.
Have tried this on two different servers (one local, one remote) and have the same issue.
Started fresh with a new WP+WC install, created a blank theme, functions.php that does the above on init code. Same exact issue.
php wordpress session woocommerce
Simply trying to store and retrieve unregistered customer data from page to page in a custom checkout template. I've stripped it down to the bare bones to try to pinpoint the issue.
This
<?php
$customer = WC()->customer;
$customer->set_billing_first_name("WORKING!!!");
$customer->save();
var_dump($customer->get_billing());
?>
Outputs this
array (size=2)
'country' => string 'US' (length=2)
'first_name' => string 'WORKING!!!' (length=10)
But then this
<?php
$customer = WC()->customer;
//$customer->set_billing_first_name("WORKING!!!");
//$customer->save();
var_dump($customer->get_billing());
?>
Outputs this
array (size=1)
'country' => string 'US' (length=2)
Even though I should still be firmly within the same session, and therefore should get the data stored before the comments. All I did was refresh the page after commenting out those two lines.
Am I completely wrong about these methods?
Checked
Environment is configured entirely correctly. Even had someone else double-check it for me. URLs, caches, etc.
It does appear to work when logged in, but the vast majority of users never do so that's not very helpful.
Have tried this on two different servers (one local, one remote) and have the same issue.
Started fresh with a new WP+WC install, created a blank theme, functions.php that does the above on init code. Same exact issue.
php wordpress session woocommerce
php wordpress session woocommerce
edited Nov 11 at 23:13
asked Nov 8 at 3:42
Randy Hall
2,12163775
2,12163775
1
That is a normal thing if$customer->get_id()
is0
which happens when you're not logged-in. WooCommerce stores the session identifier (the user ID or an auto-generated customer ID) in the browser's cookies, and not the superglobal$_SESSION
. Tryvar_dump( $customer->get_billing(), $customer->get_id(), WC->session->get_customer_id() )
and see the output when you're logged-in and not.
– Sally CJ
Nov 11 at 23:55
@SallyCJ ah okay so my root assumption that this stores customer data in a session is false? I am seeing thewp_woocommerce_session_xxx=yyyy
cookie passed up in the request... it there a built-in way to store this customer data temporarily?
– Randy Hall
Nov 12 at 0:02
1
Your assumption is basically true; however, the session data (other than the session identifier; e.g. cart contents) are stored in{prefix}woocommerce_sessions
table - e.g.wp_woocommerce_sessions
. And this is same to how the WordPress authentication works, where your user ID is saved in the cookie, but the rest of your session are saved in the database. You can useWC()->session->set()
to save data temporarily, which can persist across pages - but of course cookies must be enabled in the user's browser.
– Sally CJ
Nov 12 at 0:19
@SallyCJ I'm seeing the same issue, usingWC()->session
, setting a var, then commenting out the set and refreshing the page. The value I saved and successfully returned usingWC()->session->set()
andWC()->session->get()
is just flat out not there after navigation.
– Randy Hall
Nov 12 at 8:27
1
Check my answer and let me know how it goes. Hopefully it works..
– Sally CJ
Nov 12 at 10:29
add a comment |
1
That is a normal thing if$customer->get_id()
is0
which happens when you're not logged-in. WooCommerce stores the session identifier (the user ID or an auto-generated customer ID) in the browser's cookies, and not the superglobal$_SESSION
. Tryvar_dump( $customer->get_billing(), $customer->get_id(), WC->session->get_customer_id() )
and see the output when you're logged-in and not.
– Sally CJ
Nov 11 at 23:55
@SallyCJ ah okay so my root assumption that this stores customer data in a session is false? I am seeing thewp_woocommerce_session_xxx=yyyy
cookie passed up in the request... it there a built-in way to store this customer data temporarily?
– Randy Hall
Nov 12 at 0:02
1
Your assumption is basically true; however, the session data (other than the session identifier; e.g. cart contents) are stored in{prefix}woocommerce_sessions
table - e.g.wp_woocommerce_sessions
. And this is same to how the WordPress authentication works, where your user ID is saved in the cookie, but the rest of your session are saved in the database. You can useWC()->session->set()
to save data temporarily, which can persist across pages - but of course cookies must be enabled in the user's browser.
– Sally CJ
Nov 12 at 0:19
@SallyCJ I'm seeing the same issue, usingWC()->session
, setting a var, then commenting out the set and refreshing the page. The value I saved and successfully returned usingWC()->session->set()
andWC()->session->get()
is just flat out not there after navigation.
– Randy Hall
Nov 12 at 8:27
1
Check my answer and let me know how it goes. Hopefully it works..
– Sally CJ
Nov 12 at 10:29
1
1
That is a normal thing if
$customer->get_id()
is 0
which happens when you're not logged-in. WooCommerce stores the session identifier (the user ID or an auto-generated customer ID) in the browser's cookies, and not the superglobal $_SESSION
. Try var_dump( $customer->get_billing(), $customer->get_id(), WC->session->get_customer_id() )
and see the output when you're logged-in and not.– Sally CJ
Nov 11 at 23:55
That is a normal thing if
$customer->get_id()
is 0
which happens when you're not logged-in. WooCommerce stores the session identifier (the user ID or an auto-generated customer ID) in the browser's cookies, and not the superglobal $_SESSION
. Try var_dump( $customer->get_billing(), $customer->get_id(), WC->session->get_customer_id() )
and see the output when you're logged-in and not.– Sally CJ
Nov 11 at 23:55
@SallyCJ ah okay so my root assumption that this stores customer data in a session is false? I am seeing the
wp_woocommerce_session_xxx=yyyy
cookie passed up in the request... it there a built-in way to store this customer data temporarily?– Randy Hall
Nov 12 at 0:02
@SallyCJ ah okay so my root assumption that this stores customer data in a session is false? I am seeing the
wp_woocommerce_session_xxx=yyyy
cookie passed up in the request... it there a built-in way to store this customer data temporarily?– Randy Hall
Nov 12 at 0:02
1
1
Your assumption is basically true; however, the session data (other than the session identifier; e.g. cart contents) are stored in
{prefix}woocommerce_sessions
table - e.g. wp_woocommerce_sessions
. And this is same to how the WordPress authentication works, where your user ID is saved in the cookie, but the rest of your session are saved in the database. You can use WC()->session->set()
to save data temporarily, which can persist across pages - but of course cookies must be enabled in the user's browser.– Sally CJ
Nov 12 at 0:19
Your assumption is basically true; however, the session data (other than the session identifier; e.g. cart contents) are stored in
{prefix}woocommerce_sessions
table - e.g. wp_woocommerce_sessions
. And this is same to how the WordPress authentication works, where your user ID is saved in the cookie, but the rest of your session are saved in the database. You can use WC()->session->set()
to save data temporarily, which can persist across pages - but of course cookies must be enabled in the user's browser.– Sally CJ
Nov 12 at 0:19
@SallyCJ I'm seeing the same issue, using
WC()->session
, setting a var, then commenting out the set and refreshing the page. The value I saved and successfully returned using WC()->session->set()
and WC()->session->get()
is just flat out not there after navigation.– Randy Hall
Nov 12 at 8:27
@SallyCJ I'm seeing the same issue, using
WC()->session
, setting a var, then commenting out the set and refreshing the page. The value I saved and successfully returned using WC()->session->set()
and WC()->session->get()
is just flat out not there after navigation.– Randy Hall
Nov 12 at 8:27
1
1
Check my answer and let me know how it goes. Hopefully it works..
– Sally CJ
Nov 12 at 10:29
Check my answer and let me know how it goes. Hopefully it works..
– Sally CJ
Nov 12 at 10:29
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
If $customer->save()
doesn't persist the changes you made to the customer's data (e.g. $customer->set_billing_first_name('Test')
), then it's likely because the customer is not registered to the site or not logged-in, where $customer->get_id()
is 0
.
And that is normal because the user's ID or the session's ID is required in order to properly save the changes and make it persistent across different pages.
So when the user is not registered/logged-in, WooCommerce doesn't start its session until the user logs in, or that he/she added a product into the cart.
But you can manually start the session, like so: (add the code to the active theme's functions.php
file)
add_action( 'woocommerce_init', function(){
if ( ! WC()->session->has_session() ) {
WC()->session->set_customer_session_cookie( true );
}
} );
And then, changes to the customer's data would then be carried on to other pages so long as cookies are enabled on the browser, because just like WordPress, WooCommerce stores its session ID (the user ID or an auto-generated ID/hash) in the cookies — and the session ID is used to set/retrieve the session data in the database — the table name is woocommerce_sessions
if without any table prefix.
Try this after starting the WooCommerce session:
$customer = WC()->customer;
// Change 'Test' if necessary - e.g. 'Something unique 123'
if ( 'Test' !== $customer->get_billing_first_name() ) {
$customer->set_billing_first_name( 'Test' );
echo 'First name added to session<br>';
} else {
echo 'First name read from session<br>';
}
And this one — you should see a new date on each page load: (well, the one you've set previously)
echo WC()->session->get( 'test', 'None set' ) . '<br>';
WC()->session->set( 'test', current_time( 'mysql' ) );
echo WC()->session->get( 'test', 'It can't be empty' );
You are my hero today. I would seriously pay you to answer my questions about WP. So many gaps in my knowledge...
– Randy Hall
Nov 13 at 2:23
1
Well, I always learned from people's code, and eventually became better in time. And I'm sure you too can. :) But hey, I also still have gaps in my knowledge because nobody is perfect... xD And you can always ask your question on Stack Overflow - or for WordPress-specific like creating custom WordPress REST API endpoints, then you should ask it on WordPress Stack Exchange. (Note though, WooCommerce questions are off-topic there..)
– Sally CJ
Nov 13 at 10:06
Been stuck on this one for days, you seem like you understand the bones much better than I do stackoverflow.com/questions/53362482/…
– Randy Hall
16 hours ago
add a comment |
up vote
0
down vote
Are you using the Url set in Wordpress? It seems that it stores the cookie based on the url configured in the app rather than the actual one.
Hope this helps.
Source: https://en.blogpascher.com/wordpress-tutorial/How-correct-the-loss-of-session-on-wordpress
This is actually a local copy of my site. Do you have a quick reference for where/what settings to check?
– Randy Hall
Nov 11 at 0:10
Either in wp-config.php or in the interface under General Settings
– Andrei Dumitrescu-Tudor
Nov 11 at 0:12
Check WP_SITEURL In wp-config.php
– Andrei Dumitrescu-Tudor
Nov 11 at 0:14
Interestingly, there is no WP_SITEURL set in the wp-config.php in the root of this site. As in the property is not listed. This is a site that is hosted on wpengine and they do have some custom settings in here, but I'm uncertain if that would have any effect. But I like this train of thought, working through more now
– Randy Hall
Nov 11 at 0:28
It is also in the interface codex.wordpress.org/Changing_The_Site_URL
– Andrei Dumitrescu-Tudor
Nov 11 at 0:32
|
show 1 more comment
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
If $customer->save()
doesn't persist the changes you made to the customer's data (e.g. $customer->set_billing_first_name('Test')
), then it's likely because the customer is not registered to the site or not logged-in, where $customer->get_id()
is 0
.
And that is normal because the user's ID or the session's ID is required in order to properly save the changes and make it persistent across different pages.
So when the user is not registered/logged-in, WooCommerce doesn't start its session until the user logs in, or that he/she added a product into the cart.
But you can manually start the session, like so: (add the code to the active theme's functions.php
file)
add_action( 'woocommerce_init', function(){
if ( ! WC()->session->has_session() ) {
WC()->session->set_customer_session_cookie( true );
}
} );
And then, changes to the customer's data would then be carried on to other pages so long as cookies are enabled on the browser, because just like WordPress, WooCommerce stores its session ID (the user ID or an auto-generated ID/hash) in the cookies — and the session ID is used to set/retrieve the session data in the database — the table name is woocommerce_sessions
if without any table prefix.
Try this after starting the WooCommerce session:
$customer = WC()->customer;
// Change 'Test' if necessary - e.g. 'Something unique 123'
if ( 'Test' !== $customer->get_billing_first_name() ) {
$customer->set_billing_first_name( 'Test' );
echo 'First name added to session<br>';
} else {
echo 'First name read from session<br>';
}
And this one — you should see a new date on each page load: (well, the one you've set previously)
echo WC()->session->get( 'test', 'None set' ) . '<br>';
WC()->session->set( 'test', current_time( 'mysql' ) );
echo WC()->session->get( 'test', 'It can't be empty' );
You are my hero today. I would seriously pay you to answer my questions about WP. So many gaps in my knowledge...
– Randy Hall
Nov 13 at 2:23
1
Well, I always learned from people's code, and eventually became better in time. And I'm sure you too can. :) But hey, I also still have gaps in my knowledge because nobody is perfect... xD And you can always ask your question on Stack Overflow - or for WordPress-specific like creating custom WordPress REST API endpoints, then you should ask it on WordPress Stack Exchange. (Note though, WooCommerce questions are off-topic there..)
– Sally CJ
Nov 13 at 10:06
Been stuck on this one for days, you seem like you understand the bones much better than I do stackoverflow.com/questions/53362482/…
– Randy Hall
16 hours ago
add a comment |
up vote
2
down vote
accepted
If $customer->save()
doesn't persist the changes you made to the customer's data (e.g. $customer->set_billing_first_name('Test')
), then it's likely because the customer is not registered to the site or not logged-in, where $customer->get_id()
is 0
.
And that is normal because the user's ID or the session's ID is required in order to properly save the changes and make it persistent across different pages.
So when the user is not registered/logged-in, WooCommerce doesn't start its session until the user logs in, or that he/she added a product into the cart.
But you can manually start the session, like so: (add the code to the active theme's functions.php
file)
add_action( 'woocommerce_init', function(){
if ( ! WC()->session->has_session() ) {
WC()->session->set_customer_session_cookie( true );
}
} );
And then, changes to the customer's data would then be carried on to other pages so long as cookies are enabled on the browser, because just like WordPress, WooCommerce stores its session ID (the user ID or an auto-generated ID/hash) in the cookies — and the session ID is used to set/retrieve the session data in the database — the table name is woocommerce_sessions
if without any table prefix.
Try this after starting the WooCommerce session:
$customer = WC()->customer;
// Change 'Test' if necessary - e.g. 'Something unique 123'
if ( 'Test' !== $customer->get_billing_first_name() ) {
$customer->set_billing_first_name( 'Test' );
echo 'First name added to session<br>';
} else {
echo 'First name read from session<br>';
}
And this one — you should see a new date on each page load: (well, the one you've set previously)
echo WC()->session->get( 'test', 'None set' ) . '<br>';
WC()->session->set( 'test', current_time( 'mysql' ) );
echo WC()->session->get( 'test', 'It can't be empty' );
You are my hero today. I would seriously pay you to answer my questions about WP. So many gaps in my knowledge...
– Randy Hall
Nov 13 at 2:23
1
Well, I always learned from people's code, and eventually became better in time. And I'm sure you too can. :) But hey, I also still have gaps in my knowledge because nobody is perfect... xD And you can always ask your question on Stack Overflow - or for WordPress-specific like creating custom WordPress REST API endpoints, then you should ask it on WordPress Stack Exchange. (Note though, WooCommerce questions are off-topic there..)
– Sally CJ
Nov 13 at 10:06
Been stuck on this one for days, you seem like you understand the bones much better than I do stackoverflow.com/questions/53362482/…
– Randy Hall
16 hours ago
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
If $customer->save()
doesn't persist the changes you made to the customer's data (e.g. $customer->set_billing_first_name('Test')
), then it's likely because the customer is not registered to the site or not logged-in, where $customer->get_id()
is 0
.
And that is normal because the user's ID or the session's ID is required in order to properly save the changes and make it persistent across different pages.
So when the user is not registered/logged-in, WooCommerce doesn't start its session until the user logs in, or that he/she added a product into the cart.
But you can manually start the session, like so: (add the code to the active theme's functions.php
file)
add_action( 'woocommerce_init', function(){
if ( ! WC()->session->has_session() ) {
WC()->session->set_customer_session_cookie( true );
}
} );
And then, changes to the customer's data would then be carried on to other pages so long as cookies are enabled on the browser, because just like WordPress, WooCommerce stores its session ID (the user ID or an auto-generated ID/hash) in the cookies — and the session ID is used to set/retrieve the session data in the database — the table name is woocommerce_sessions
if without any table prefix.
Try this after starting the WooCommerce session:
$customer = WC()->customer;
// Change 'Test' if necessary - e.g. 'Something unique 123'
if ( 'Test' !== $customer->get_billing_first_name() ) {
$customer->set_billing_first_name( 'Test' );
echo 'First name added to session<br>';
} else {
echo 'First name read from session<br>';
}
And this one — you should see a new date on each page load: (well, the one you've set previously)
echo WC()->session->get( 'test', 'None set' ) . '<br>';
WC()->session->set( 'test', current_time( 'mysql' ) );
echo WC()->session->get( 'test', 'It can't be empty' );
If $customer->save()
doesn't persist the changes you made to the customer's data (e.g. $customer->set_billing_first_name('Test')
), then it's likely because the customer is not registered to the site or not logged-in, where $customer->get_id()
is 0
.
And that is normal because the user's ID or the session's ID is required in order to properly save the changes and make it persistent across different pages.
So when the user is not registered/logged-in, WooCommerce doesn't start its session until the user logs in, or that he/she added a product into the cart.
But you can manually start the session, like so: (add the code to the active theme's functions.php
file)
add_action( 'woocommerce_init', function(){
if ( ! WC()->session->has_session() ) {
WC()->session->set_customer_session_cookie( true );
}
} );
And then, changes to the customer's data would then be carried on to other pages so long as cookies are enabled on the browser, because just like WordPress, WooCommerce stores its session ID (the user ID or an auto-generated ID/hash) in the cookies — and the session ID is used to set/retrieve the session data in the database — the table name is woocommerce_sessions
if without any table prefix.
Try this after starting the WooCommerce session:
$customer = WC()->customer;
// Change 'Test' if necessary - e.g. 'Something unique 123'
if ( 'Test' !== $customer->get_billing_first_name() ) {
$customer->set_billing_first_name( 'Test' );
echo 'First name added to session<br>';
} else {
echo 'First name read from session<br>';
}
And this one — you should see a new date on each page load: (well, the one you've set previously)
echo WC()->session->get( 'test', 'None set' ) . '<br>';
WC()->session->set( 'test', current_time( 'mysql' ) );
echo WC()->session->get( 'test', 'It can't be empty' );
edited Nov 12 at 10:45
answered Nov 12 at 10:25
Sally CJ
7,2722416
7,2722416
You are my hero today. I would seriously pay you to answer my questions about WP. So many gaps in my knowledge...
– Randy Hall
Nov 13 at 2:23
1
Well, I always learned from people's code, and eventually became better in time. And I'm sure you too can. :) But hey, I also still have gaps in my knowledge because nobody is perfect... xD And you can always ask your question on Stack Overflow - or for WordPress-specific like creating custom WordPress REST API endpoints, then you should ask it on WordPress Stack Exchange. (Note though, WooCommerce questions are off-topic there..)
– Sally CJ
Nov 13 at 10:06
Been stuck on this one for days, you seem like you understand the bones much better than I do stackoverflow.com/questions/53362482/…
– Randy Hall
16 hours ago
add a comment |
You are my hero today. I would seriously pay you to answer my questions about WP. So many gaps in my knowledge...
– Randy Hall
Nov 13 at 2:23
1
Well, I always learned from people's code, and eventually became better in time. And I'm sure you too can. :) But hey, I also still have gaps in my knowledge because nobody is perfect... xD And you can always ask your question on Stack Overflow - or for WordPress-specific like creating custom WordPress REST API endpoints, then you should ask it on WordPress Stack Exchange. (Note though, WooCommerce questions are off-topic there..)
– Sally CJ
Nov 13 at 10:06
Been stuck on this one for days, you seem like you understand the bones much better than I do stackoverflow.com/questions/53362482/…
– Randy Hall
16 hours ago
You are my hero today. I would seriously pay you to answer my questions about WP. So many gaps in my knowledge...
– Randy Hall
Nov 13 at 2:23
You are my hero today. I would seriously pay you to answer my questions about WP. So many gaps in my knowledge...
– Randy Hall
Nov 13 at 2:23
1
1
Well, I always learned from people's code, and eventually became better in time. And I'm sure you too can. :) But hey, I also still have gaps in my knowledge because nobody is perfect... xD And you can always ask your question on Stack Overflow - or for WordPress-specific like creating custom WordPress REST API endpoints, then you should ask it on WordPress Stack Exchange. (Note though, WooCommerce questions are off-topic there..)
– Sally CJ
Nov 13 at 10:06
Well, I always learned from people's code, and eventually became better in time. And I'm sure you too can. :) But hey, I also still have gaps in my knowledge because nobody is perfect... xD And you can always ask your question on Stack Overflow - or for WordPress-specific like creating custom WordPress REST API endpoints, then you should ask it on WordPress Stack Exchange. (Note though, WooCommerce questions are off-topic there..)
– Sally CJ
Nov 13 at 10:06
Been stuck on this one for days, you seem like you understand the bones much better than I do stackoverflow.com/questions/53362482/…
– Randy Hall
16 hours ago
Been stuck on this one for days, you seem like you understand the bones much better than I do stackoverflow.com/questions/53362482/…
– Randy Hall
16 hours ago
add a comment |
up vote
0
down vote
Are you using the Url set in Wordpress? It seems that it stores the cookie based on the url configured in the app rather than the actual one.
Hope this helps.
Source: https://en.blogpascher.com/wordpress-tutorial/How-correct-the-loss-of-session-on-wordpress
This is actually a local copy of my site. Do you have a quick reference for where/what settings to check?
– Randy Hall
Nov 11 at 0:10
Either in wp-config.php or in the interface under General Settings
– Andrei Dumitrescu-Tudor
Nov 11 at 0:12
Check WP_SITEURL In wp-config.php
– Andrei Dumitrescu-Tudor
Nov 11 at 0:14
Interestingly, there is no WP_SITEURL set in the wp-config.php in the root of this site. As in the property is not listed. This is a site that is hosted on wpengine and they do have some custom settings in here, but I'm uncertain if that would have any effect. But I like this train of thought, working through more now
– Randy Hall
Nov 11 at 0:28
It is also in the interface codex.wordpress.org/Changing_The_Site_URL
– Andrei Dumitrescu-Tudor
Nov 11 at 0:32
|
show 1 more comment
up vote
0
down vote
Are you using the Url set in Wordpress? It seems that it stores the cookie based on the url configured in the app rather than the actual one.
Hope this helps.
Source: https://en.blogpascher.com/wordpress-tutorial/How-correct-the-loss-of-session-on-wordpress
This is actually a local copy of my site. Do you have a quick reference for where/what settings to check?
– Randy Hall
Nov 11 at 0:10
Either in wp-config.php or in the interface under General Settings
– Andrei Dumitrescu-Tudor
Nov 11 at 0:12
Check WP_SITEURL In wp-config.php
– Andrei Dumitrescu-Tudor
Nov 11 at 0:14
Interestingly, there is no WP_SITEURL set in the wp-config.php in the root of this site. As in the property is not listed. This is a site that is hosted on wpengine and they do have some custom settings in here, but I'm uncertain if that would have any effect. But I like this train of thought, working through more now
– Randy Hall
Nov 11 at 0:28
It is also in the interface codex.wordpress.org/Changing_The_Site_URL
– Andrei Dumitrescu-Tudor
Nov 11 at 0:32
|
show 1 more comment
up vote
0
down vote
up vote
0
down vote
Are you using the Url set in Wordpress? It seems that it stores the cookie based on the url configured in the app rather than the actual one.
Hope this helps.
Source: https://en.blogpascher.com/wordpress-tutorial/How-correct-the-loss-of-session-on-wordpress
Are you using the Url set in Wordpress? It seems that it stores the cookie based on the url configured in the app rather than the actual one.
Hope this helps.
Source: https://en.blogpascher.com/wordpress-tutorial/How-correct-the-loss-of-session-on-wordpress
answered Nov 11 at 0:08
Andrei Dumitrescu-Tudor
1697
1697
This is actually a local copy of my site. Do you have a quick reference for where/what settings to check?
– Randy Hall
Nov 11 at 0:10
Either in wp-config.php or in the interface under General Settings
– Andrei Dumitrescu-Tudor
Nov 11 at 0:12
Check WP_SITEURL In wp-config.php
– Andrei Dumitrescu-Tudor
Nov 11 at 0:14
Interestingly, there is no WP_SITEURL set in the wp-config.php in the root of this site. As in the property is not listed. This is a site that is hosted on wpengine and they do have some custom settings in here, but I'm uncertain if that would have any effect. But I like this train of thought, working through more now
– Randy Hall
Nov 11 at 0:28
It is also in the interface codex.wordpress.org/Changing_The_Site_URL
– Andrei Dumitrescu-Tudor
Nov 11 at 0:32
|
show 1 more comment
This is actually a local copy of my site. Do you have a quick reference for where/what settings to check?
– Randy Hall
Nov 11 at 0:10
Either in wp-config.php or in the interface under General Settings
– Andrei Dumitrescu-Tudor
Nov 11 at 0:12
Check WP_SITEURL In wp-config.php
– Andrei Dumitrescu-Tudor
Nov 11 at 0:14
Interestingly, there is no WP_SITEURL set in the wp-config.php in the root of this site. As in the property is not listed. This is a site that is hosted on wpengine and they do have some custom settings in here, but I'm uncertain if that would have any effect. But I like this train of thought, working through more now
– Randy Hall
Nov 11 at 0:28
It is also in the interface codex.wordpress.org/Changing_The_Site_URL
– Andrei Dumitrescu-Tudor
Nov 11 at 0:32
This is actually a local copy of my site. Do you have a quick reference for where/what settings to check?
– Randy Hall
Nov 11 at 0:10
This is actually a local copy of my site. Do you have a quick reference for where/what settings to check?
– Randy Hall
Nov 11 at 0:10
Either in wp-config.php or in the interface under General Settings
– Andrei Dumitrescu-Tudor
Nov 11 at 0:12
Either in wp-config.php or in the interface under General Settings
– Andrei Dumitrescu-Tudor
Nov 11 at 0:12
Check WP_SITEURL In wp-config.php
– Andrei Dumitrescu-Tudor
Nov 11 at 0:14
Check WP_SITEURL In wp-config.php
– Andrei Dumitrescu-Tudor
Nov 11 at 0:14
Interestingly, there is no WP_SITEURL set in the wp-config.php in the root of this site. As in the property is not listed. This is a site that is hosted on wpengine and they do have some custom settings in here, but I'm uncertain if that would have any effect. But I like this train of thought, working through more now
– Randy Hall
Nov 11 at 0:28
Interestingly, there is no WP_SITEURL set in the wp-config.php in the root of this site. As in the property is not listed. This is a site that is hosted on wpengine and they do have some custom settings in here, but I'm uncertain if that would have any effect. But I like this train of thought, working through more now
– Randy Hall
Nov 11 at 0:28
It is also in the interface codex.wordpress.org/Changing_The_Site_URL
– Andrei Dumitrescu-Tudor
Nov 11 at 0:32
It is also in the interface codex.wordpress.org/Changing_The_Site_URL
– Andrei Dumitrescu-Tudor
Nov 11 at 0:32
|
show 1 more comment
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53201243%2fwordpress-wc-session-not-carried-to-next-page%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
That is a normal thing if
$customer->get_id()
is0
which happens when you're not logged-in. WooCommerce stores the session identifier (the user ID or an auto-generated customer ID) in the browser's cookies, and not the superglobal$_SESSION
. Tryvar_dump( $customer->get_billing(), $customer->get_id(), WC->session->get_customer_id() )
and see the output when you're logged-in and not.– Sally CJ
Nov 11 at 23:55
@SallyCJ ah okay so my root assumption that this stores customer data in a session is false? I am seeing the
wp_woocommerce_session_xxx=yyyy
cookie passed up in the request... it there a built-in way to store this customer data temporarily?– Randy Hall
Nov 12 at 0:02
1
Your assumption is basically true; however, the session data (other than the session identifier; e.g. cart contents) are stored in
{prefix}woocommerce_sessions
table - e.g.wp_woocommerce_sessions
. And this is same to how the WordPress authentication works, where your user ID is saved in the cookie, but the rest of your session are saved in the database. You can useWC()->session->set()
to save data temporarily, which can persist across pages - but of course cookies must be enabled in the user's browser.– Sally CJ
Nov 12 at 0:19
@SallyCJ I'm seeing the same issue, using
WC()->session
, setting a var, then commenting out the set and refreshing the page. The value I saved and successfully returned usingWC()->session->set()
andWC()->session->get()
is just flat out not there after navigation.– Randy Hall
Nov 12 at 8:27
1
Check my answer and let me know how it goes. Hopefully it works..
– Sally CJ
Nov 12 at 10:29