1. Home
  2. Getting Started
  3. Troubleshooting Caching & Session Issues

Troubleshooting Caching & Session Issues

Sometimes you or your site visitors might experience issues related to caching or sessions while using WP Simple Pay. This usually happens because of performance enhancements your web host has in place for your sites.

How to Detect a Caching or Session Issue

Detecting if your issue is related to caching or sessions can be hard to determine. One of the biggest signs is if you or your customers see this message after submitting a payment:

An error occurred, but your charge may have gone through. Please contact the site admin.

Back in your Stripe dashboard, if you see charges are going through even when customers are seeing this message, it might be due to a caching or session issue.

Excluding Confirmation Pages from Cache

Simply put, you’ll need to make sure your payment success and failure pages are excluded from any site caching. You may have caching configured at the host level or with other plugins depending on your setup.

By default, WP Simple Pay turns off caching for the payment success and failure pages by using the standard DONOTCACHEPAGE constant. Most popular WordPress caching plugins will detect this constant and disable caching on these pages if it’s set to true. These caching plugins should also allow you to specify which pages to exclude from caching. If you need to specify additional page cache exclusions via code, you can start with this filter hook example from our code snippet library.

Some web hosts implement aggressive server caching that you have no direct control over. In these cases, you’ll need to contact your web host and specify which pages (URLs) to exclude from caching.

Purging the Cache

Server-Side Cache

Some web hosts will use advanced caching techniques to automatically make your site run more smoothly. This is great, but you might find that sometimes you will need to purge this cache to make sure your forms are using the latest version of the plugin files. You will want to look around in your WordPress admin for some kind of “purge cache” button to clear this all out. If you cannot find one then you can contact your host to ask them for assistance. Below is an example of how this looks for SiteGround.

Browser Cache

Some website changes might require you to clear the browser cache. This mostly affects JavaScript changes and usually when you are making frequent updates and testing. These will most likely never be a problem for you, but it is good to be aware just in case.

The best solution for this is to just clear the browser cache and then reload the page. Some browsers, such as Google Chrome, let you perform a “hard reload” of the page. To do this in Chrome, first open the console log window (Cmd-Alt-J or F12). Next, right-click the reload button and select “Empty Cache and Hard Reload”. Similar functionality should exist in other browsers as well.

Switching to Native PHP Sessions

If you’re still getting the above error message after troubleshooting caching issues, it may be a session issue.

By default, WP Simple Pay overrides the use of native PHP sessions and uses a custom table temporary storage method instead. This is to improve performance and is common practice both in WordPress core as well as other e-commerce plugins.

In a few cases, this method may not work with some hosting configurations. To force the use of native PHP sessions, you’ll need to add this constant to your wp-config.php file.

define( 'SIMPLE_PAY_USE_PHP_SESSIONS', true );

If needed, see how to edit your wp-config.php file. Alternatively, you can use the simpay_use_php_sessions filter hook.

Note for Pantheon Customers

After extensive testing with various popular web hosts, the only host where our method of overriding native PHP sessions didn’t work was with Pantheon.

If you host with Pantheon, they prefer to override and handle PHP sessions in a method specific to their server architecture, again for performance reasons.

In short, you simply need to install their free Native PHP Sessions plugin on your Pantheon-hosted sites. In turn, WP Simple Pay will detect if this plugin is active and defer to it’s handling of PHP sessions.

Updated on February 15, 2018

Was this article helpful?

Related Articles