GetSupportX
Portal sign-in docs
Portal sign-in guide

WordPress & WooCommerce

For WordPress sites where customers log in: a WooCommerce “My account” page, a members area, or any site with WordPress user accounts.

Plugin, no code

Easiest: the GetSupportX plugin

  1. Download the plugin

    It isn’t on WordPress.org, so download it with the button below.

  2. Upload it

    In WordPress, go to Plugins → Add New → Upload Plugin and activate it.

  3. Click Connect

    Open GetSupportX → Settings, click Connect and pick your workspace. Chat, portal sign-in and logged-in customer details are set up for you. Nothing to copy or paste.

Download the plugin

Always the latest version.

With the plugin connected you can skip the rest of this page, apart from checking it works.

From plugin version 0.5.2, a customer who opened a link to one of their requests lands on that request after signing in. With an older plugin (0.5.1 or earlier) they land on the portal home. The code on this page does it too.

Or paste the code yourself

In GetSupportX, open Settings → Help center & portal → Portal sign-in and switch on Sign in through your website. Answer What is your website built on? with WordPress / WooCommerce. Then click Prefer to paste code instead? to see the steps.

Under 1 · Secret key, click Create secret key. Copy the key straight away: it is shown once. The code on this page needs it.

Copy the code from 2 · Add the code to your website: your callback URL is already filled in there. Copying the code from this page instead? Replace the whole https://<your-help-center>/portal/handoff address with the Callback URL Settings shows under For developers in step 2. Don’t build it by hand: it isn’t the same for every help center.

Steps

  1. Paste the code at the bottom of your child theme’s functions.php

    In WordPress: Appearance → Theme File Editor.

  2. Put in your secret key

    Replace PASTE-YOUR-SECRET-HERE with your secret key. Copied the code from Settings? Your callback URL is already in it. Copied it from this page? Also replace the whole https://<your-help-center>/portal/handoff address with the Callback URL from Settings (under For developers in step 2).

  3. Set your sign-in link

    Your website’s address followed by /?gsx_support=1, for example https://yourwebsite.com/?gsx_support=1.

The code

functions.php (child theme)
<?php
/**
 * GetSupportX sign-in — paste this ONCE at the bottom of your child theme's
 * functions.php (Appearance → Theme File Editor), then paste your secret below.
 *
 * Your sign-in link is:  https://yourwebsite.com/?gsx_support=1
 * Put exactly that in GetSupportX → Settings → Portal sign-in → Sign-in link.
 */
define( 'GSX_SSO_SECRET', 'PASTE-YOUR-SECRET-HERE' );
define( 'GSX_CALLBACK',   'https://<your-help-center>/portal/handoff' );

add_action( 'init', function () {
  if ( ! isset( $_GET['gsx_support'] ) ) return;
  nocache_headers(); // the redirect below signs one person in — never cache it

  // Not logged in? WordPress sends them to log in, then straight back to this
  // exact address (gsx_return included).
  if ( ! is_user_logged_in() ) { auth_redirect(); exit; }

  // The portal page they were heading to (?gsx_return=), passed on below.
  $back = isset( $_GET['gsx_return'] ) && is_string( $_GET['gsx_return'] ) ? wp_unslash( $_GET['gsx_return'] ) : '';

  // The same customer id the GetSupportX plugin uses, so you can switch between
  // this code and the plugin at any time without losing anyone's history.
  $p      = wp_parse_url( home_url() );
  $scheme = strtolower( isset( $p['scheme'] ) ? $p['scheme'] : 'https' );
  $port   = isset( $p['port'] ) ? (int) $p['port'] : 0;
  if ( ( 'https' === $scheme && 443 === $port ) || ( 'http' === $scheme && 80 === $port ) ) $port = 0;
  $site   = $scheme . '://' . strtolower( $p['host'] ) . ( $port ? ':' . $port : '' );

  $u = wp_get_current_user();
  $payload = array(
    'externalId'       => 'wp:' . substr( hash( 'sha256', $site ), 0, 12 ) . ':' . $u->ID,
    'site'             => $site,
    'legacyExternalId' => (string) $u->ID, // keeps customers an older snippet created
    'email'            => $u->user_email,
    'name'             => $u->display_name,

    // OPTIONAL — delete any line whose data you do not have.
    'role'    => implode( ', ', (array) $u->roles ),
    'website' => $u->user_url,
    'phone'   => get_user_meta( $u->ID, 'billing_phone', true ),   // WooCommerce
    'company' => get_user_meta( $u->ID, 'billing_company', true ), // WooCommerce

    'iat' => time(),
    'exp' => time() + 300,
    'jti' => bin2hex( random_bytes( 16 ) ), // one-time id: this exact link works once
  );

  // WooCommerce spend + order count; skipped on a site without WooCommerce.
  if ( function_exists( 'wc_get_customer_total_spent' ) ) {
    $payload['ltv']        = (float) wc_get_customer_total_spent( $u->ID );
    $payload['attributes'] = array( 'orders' => (int) wc_get_customer_order_count( $u->ID ) );
  }

  // Drop empty values so a blank field never overwrites something an agent typed.
  $payload = array_filter( $payload, function ( $v ) { return $v !== '' && $v !== null; } );

  $b64 = base64_encode( wp_json_encode( $payload ) );
  $sig = hash_hmac( 'sha256', $b64, GSX_SSO_SECRET );

  $url = GSX_CALLBACK . '?payload=' . rawurlencode( $b64 ) . '&sig=' . $sig;
  // Only a plain path — GetSupportX checks it again before using it.
  if ( '/' === substr( $back, 0, 1 ) && '//' !== substr( $back, 0, 2 ) && '/\\' !== substr( $back, 0, 2 ) ) {
    $url .= '&redirect=' . rawurlencode( $back );
  }

  wp_redirect( $url );
  exit;
} );

Every version of this code signs the same way. The protocol reference lists each field and rule, including the optional customer details (plan, phone and more) you can add.

Check it works

  1. Save your sign-in link

    In Settings → Help center & portal → Portal sign-in, enter it under 3 · Sign-in link (for example https://yourwebsite.com/?gsx_support=1) and click Save. With the plugin, Connect saves it for you. What is the sign-in link?

  2. Click Test sign-in

    Under Check it works. We open your link as a visitor who isn’t logged in. “Your sign-in link is live” means your link sent that visitor somewhere other than your homepage or the portal, and names the address. Check that address is your login page.

  3. Try it as a customer

    Log in to your website, then open your sign-in link. You should land in your portal, signed in. If not, Check it works lists the reason under recent failed sign-ins, and Troubleshooting says how to fix it.

Good to know

  • Use a child theme. Updating a theme replaces its functions.php, and the code would go with it.
  • Some hosts switch the Theme File Editor off. If you can’t find it, use the plugin instead.
  • Customers who aren’t logged in are sent to the WordPress login page first, then straight on to the portal.
  • A customer who opened a link to one of their requests lands on that request after signing in. The code on this page does this; so does the plugin from version 0.5.2 (with 0.5.1 or earlier they land on the portal home).
  • With WooCommerce, the code also sends the customer’s phone, company, total spend and order count, so your team sees them next to each request.
  • Using a caching plugin or a CDN? Exclude addresses containing gsx_support from the cache. The code already tells caches not to keep it.
  • The code and the plugin give customers the same ids, so you can switch from one to the other later without anyone losing their history.

Read next