WooCommerce Best Practices

WooCommerce is the leading eCommerce plugin for WordPress. Learn how to leverage the power of WooCommerce with the performance and security of WP Engine.


WooCommerce Development Best Practices

  • WooCommerce recommends adding custom code to a plugin (such as Jetpack) or child theme. Child themes inherit the looks and functions of the original theme but allow you to add custom styles and functions that override them.
  • Use WooCommerce hooks and filters in your theme or plugin code. These hooks and filters have been developed and tested by the WordPress community, so they’re the ideal way to leverage WooCommerce functionality.
  • Keep on top of updates from the WooCommerce team. Their developers are constantly releasing updates for performance or to add features. Follow their developer blog to keep yourself up to date.
  • Leverage the WordPress REST API endpoints for WooCommerce to safely hook into your site with any number of apps and services. Create a “headless” site or even manage a single product base across multiple sites.

Encrypt User Information

  • Use secure payment gateways like Paypal, Authorize.net, and Stripe to ensure user payment information isn’t stored in your own site’s database.
  • The payment gateway itself is encrypted, but the pages taking in that information should be secured too. Secure checkout and login pages, which transmit secure customer and order information, by adding an SSL.
  • Read about WP Engine’s security environment and see how we’re protecting your site at a server level.

Effective Cache with WooCommerce

Keeping your site cacheable is one of the most important steps to ensure it can perform its best. However, caching shouldn’t impair standard and expected actions, like logging in or completing an order. We’ve taken steps to ensure your site is highly functional from the start.

Default Excluded Pages on All Sites

store
cart
checkout
check-out

If WP Engine detects the WooCommerce on your site, we will automatically apply additional cache exclusions.

WooCommerce Excluded Pages

products-compare
coupons
my-account/lost-password
wp-json/wc
wc-api

WooCommerce Excluded Arguments

add-to-cart=.+
wp-api=.+

WooCommerce Excluded Cookies

woocommerce_items_in_cart=[1-9]+,
wp_woocommerce_session
woocommerce_cart_hash

NOTE: If you are using custom page URLs (EX: /basket) those pages will need to be excluded manually by reaching out to our Support team.

Purge Cache

Purging server cache is essential to any developer or site manager. Learn how to purge server caches in our guide.

If you’ve updated a page but don’t want to reset all caches, purging individual page cache by URL is possible as well using the WP Engine Advanced Cache plugin.


Deploy WooCommerce Site

If you use a STG/DEV environment to test or draft changes, there are some general best practices to follow when copying between them. These steps are particularly important because your PRD WooCommerce site may receive orders, add products, etc. It’s important to ensure you don’t overwrite this crucial database information in Production when copying data up from STG/DEV.

If you do not intend to deploy the database to PRD, simply Copy Site as normal.

If you intend to deploy database information to PRD while also preserving database information on PRD:

  1. On Production; Export any order, product, or customer information you wish to keep
  2. Copy from Staging/Development to Production, including the database
  3. On Production; Import any data exported in Step 2

NOTE: We recommend placing the site in maintenance mode prior to beginning this process, so new information is not added. Be sure to lift maintenance mode again after.

Export/Import WooCommerce Data

There are a number of plugins and tools to ease this transition. Choosing an option largely depends on the nature of your export and, as such, your business.

WooCommerce CSV Importer/Exporter — Built-in product exporter/importer
WP All Export — Allows many options for exporting Orders, Customers, and Coupons
Export/Import Plugin For WooCommerce — Helpful for exporting Orders
WooCommerce CSV Import Suite — Paid export/import suite provided by WooCommerce
WP All Export for WooCommerce — Helpful to export/import of Products
WordPress Default Export/Import Tools  — These exports can be excessively large and there are plugins that will be better suited to exporting specific WooCommerce information

What if new pages/posts were created on STG/DEV?

The easiest solution is to use the WordPress Default Export/Import Tools to manually migrate that content from STG/DEV to PRD so it is not overwritten and lost.

If more specific export parameters are necessary, then WP All Export has more customizable export options.

Copy from Legacy Staging to Live

When copying from Legacy Staging to Live you will have the option to specify certain database tables. You will want to exclude any WooCommerce tables from this deploy if you wish to preserve database information on live.

WooCommerce Orders

wp_posts
wp_postmeta
wp_woocommerce_order_items
wp_woocommerce_order_itemmeta

WooCommerce Users

wp_users
wp_usermeta

WP CLI for WooCommerce

Did you know WooCommerce has its own set of WP CLI commands? This means you can connect to your site using our SSH gateway and run WooCommerce-specific commands, making tasks like exporting and importing even easier. For example:

Export of all customer data in CSV format and export to a file:

wp wc customer list --format=csv >> my_customers.csv

Clear the product/shop transients cache:

wp wc tool run clear_transients --user=1

For more commands:

wp wc --help

More information on WooCommerce WP CLI commands can be found here.


Improve WooCommerce Performance

With all WordPress sites we recommend a number of things like CDN and compressing images. Review our guide to learn more about improving WordPress performance.

For WordPress websites running WooCommerce, we suggest a few additional steps:

Use WooCommerce Admin

Running reports can overburden the server with excess MySQL calls to the database. WC-Admin allows you to run this functionality with JavaScript directly in your browser instead.

Check out the WooCommerce Admin plugin here.

Clear Transients

Transients can sometimes cause database bloat, which in turn slows down your site. Being able to clear these out manually is a good way to stay on the ball in terms of site performance.

  1. Login to your WordPress admin dashboard
  2. Select WooCommerce
  3. Click System Status
  4. Click Tools
  5. Click Clear Transients

Clear All Sessions

Large amounts of WooCommerce Sessions can bring down the speed of a site. This means clearing out sessions created by Woo can also help with performance.

  1. Login to your WordPress admin dashboard
  2. Select WooCommerce
  3. Click System Status
  4. Click Tools
  5. Click Clear All Sessions

In addition to clearing session it’s advised to modify your site’s robots.txt file so that bots cannot create sessions while crawling the site.

User-agent: *
Disallow: /*add-to-cart=*

Disable Cart Fragments

Cart fragments attempt to update cart information on every page. This comes through as an uncached request which can strain the server and reduce performance.
Follow our guide here to learn how and why you want to disable cart fragments.


Troubleshoot WooCommerce

When coming across issues inside the WooCommerce environment it’s good to note that it’s not always a specific issue with WooCommerce itself. The following troubleshooting steps should be followed to rule out common plugin/theme/DNS interference.

See more detailed steps in our WordPress Troubleshooting guide here.

Checkout Page Redirect Loop

WooCommerce allows for forcing the checkout page to HTTPS through its settings. A redirect loop will be caused when this setting is on in conjunction with Secure Specific URLs option in WP Engine User Portal without also defining /checkout in that setting.

The solution is to simply Secure All URLs in the WP Engine User Portal.

Missing Product Attributes

Sometimes Product Attributes may not properly show up after pushing between PRD and DEV/STG. There are a few possible fixes:

  • Delete transients
    • WooCommerce > Status > Tools > Clear Transients
  • Reset file permissions
  • Create a test attribute
    • Products > Attributes > Name the attribute > Click Add Attribute.
    • You may then see the previous attributes populate the page.
  • Deactivate and then reactivate WooCommerce
  • Run this SQL query to restore variants that may be in the trash:
    • UPDATE wp_posts SET post_status = 'publish' WHERE post_type = 'product_variation' AND post_status = 'trash';

NEXT STEP: Optimize WordPress for speed and performance

eCommerce Optimized Hosting

Go from building to launching a new store faster with WP Engine’s eCommerce solutions.