How to setup WPCargo Google Sheet Integration

Overview

The WPCargo Google Sheets Integration allows shipments from your WordPress/WPCargo system to sync automatically to Google Sheets. It supports:

One-way sync (WordPress → Google Sheet)

Two-way sync (Google Sheet → WordPress) via Apps Script

Incremental updates from oldest to newest shipments

Automatic progress tracking via Action Scheduler

Shipments are processed in the background using Action Scheduler, ensuring no data is missed, and the system continues to sync even when multiple shipments are queued.

Step 1: Prepare Google APIs

Go to Google Cloud Console

Create a new Project or use an existing one.

Enable the following APIs:

  • Google Sheets API

  • Google Drive API

Create a Service Account for your WordPress site.

Download the Service Account JSON file and place it in:

/wp-content/uploads/wpcgs/service-account.json

Share your Google Sheet with the service account email (e.g., service-account@project.iam.gserviceaccount.com) with Editor access.

 

Step 2: Configure WPCargo Google Sheets Plugin

Go to WPCargo → Settings → Google Sheets.

Upload your Service Account JSON.

Enter the Google Sheet ID where shipments will sync.

Define meta keys for the columns you want to sync (comma-separated).

Save settings.

Step 3: Manual Sync

On the Google Sheets Settings page, select optional date range (“From” / “To”).

Click Sync Now.

Progress will be tracked via a progress bar.

Logs are written to error_log for monitoring sync status.

Tip: Individual shipments can be synced via AJAX action, or bulk shipments via Action Scheduler.

Step 4: Two-Way Sync (Google Sheet → WordPress)

Important: Requires Apps Script and manual deployment.

Open your Google Sheet.

Go to Extensions → Apps Script.

Paste the following sample script:

Deploy the script as a web app with:

  • Execute as: Me (your Google account)

  • Who has access: Anyone (or domain if needed)

Add trigger to automate the script function, this allow on change action to the API

function onEdit(e) {
  if (!e) return;

  const row = e.range.getRow();
  const sheet = e.source.getActiveSheet();
  const shipmentId = sheet.getRange(row, 1).getValue(); // col A = shipment_id

  const payload = {};
  const headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];

  for (let col = 0; col < headers.length; col++) {
    payload[headers[col]] = sheet.getRange(row, col + 1).getValue();
  }

  const wpUrl = 'https://yourwebsite.com/wp-json/wpcgs/v1/update_shipment';
  const options = {
    method: 'post',
    contentType: 'application/json',
    payload: JSON.stringify({
    shipment_id: shipmentId,
    data: payload
  })
};

UrlFetchApp.fetch(wpUrl, options);
}