The Smart Send plugin for WooCommerce
WP CLI and WooCommerce CLI can be used to setup a fresh WooCommerce installation for testing.
The manual steps below are automated by bin/setup-local-dev.sh, which sets up a complete local development store — WordPress + WooCommerce with the plugin from this repository symlinked in and activated, configured with a Danish store origin, DKK currency and metric units (kg/cm), plus sample products and a Denmark shipping zone:
bin/setup-local-dev.shBy default it installs the latest WordPress and WooCommerce into ./local-dev/wordpress using SQLite (via the official SQLite Database Integration plugin), so no database server is required. Everything is configurable:
bin/setup-local-dev.sh \
--path ~/Sites/smartsend-dev \
--wp-version 6.8 \
--wc-version 9.8.5 \
--db-engine mysql --db-name wp_dev --db-user root --db-pass secret --db-host 127.0.0.1Run bin/setup-local-dev.sh --help for all options. The script is idempotent — re-running re-applies configuration without reinstalling; use --force to start over. When it finishes it prints the admin credentials and the command to start the store with WP-CLI's built-in server.
Note: SQLite is convenient for development but is not what production stores run; use --db-engine mysql when database parity matters (e.g. debugging SQL-level issues).
Either as a global composer package:
composer global require "wp-cli/wp-cli-bundle:*"or by Downloading the Phar file (recommended in eg CI/CD pipelines):
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --infoNote there is also a Github Actio for installing WP CLI.
# Download wordpress
wp core download --path=wordpress
# Go to new installation
cd wordpress
# Generate a config file
wp config create --dbhost="127.0.0.1" --dbname=wordpress --dbuser=root --dbpass=""
# Remove any previous database if needed
# wp db drop --yes
# Create the database
wp db create
# Reset DB if ever needed
# wp db reset --yes
# Install WordPress
wp core install --url=wordpress.test --title="WordPress Demo" --admin_user=wp --admin_password=wp --admin_email=wp@smartsend.io
# Install admin command
wp package install wp-cli/admin-command
# Update all plugins
wp plugin update --allWooCommerce CLI is part of WooCommerce since version 3, so simply install WooCommerce using WP Cli:
wp plugin install woocommerce --activateThe official storefront theme should be used for development and testing:
wp theme install storefront --activateInstalling the WooCommerce Sample Data serves as a good starting point:
# Install the required plugin for importing
wp plugin install wordpress-importer --activate
# Import the WooCommerce sample data
wp import "wp-content/plugins/woocommerce/sample-data/sample_products.xml" --authors=createDuring development then it makes sense symlinking the working plugin folder ./smart-send-logistics into the wordpress pluigns folder wp-content/plugins:
# Assuming that the repo is stored locally inside the folder ~/github.com/smartsendio/woocommerce
ln -s ~/github.com/smartsendio/woocommerce/smart-send-logistics "wp-content/plugins/smart-send-logistics" After which the plugin can be activated
wp plugin activate smart-send-logisticsA few modifications must be made to the default WooCommerce setup
We have not found a way to finish the Setup Wizard through CLI yet. This Wizard sets a few settings like vat settings.
wp wc shipping_zone create --user=wp --name="Denmark"
wp wc shipping_zone create --user=wp --name="Nordics"
wp wc shipping_zone create --user=wp --name="EU"configuring the countries for each shipping zone cannot be done via CLI, so doing via DB Query:
wp db query "INSERT INTO wp_woocommerce_shipping_zone_locations (zone_id, location_code, location_type) VALUES (1, 'DK', 'country')"
wp db query "INSERT INTO wp_woocommerce_shipping_zone_locations (zone_id, location_code, location_type) VALUES (2, 'SE', 'country')"
wp db query "INSERT INTO wp_woocommerce_shipping_zone_locations (zone_id, location_code, location_type) VALUES (3, 'EU', 'continent')"Adding Smart Send shipping methods
wp wc shipping_zone_method create 1 --enabled=true --settings='{"title":"Smart Send Demo"}' --method_id=smart_send_shipping --user=wpwp wc payment_gateway update bacs --user=wp --enabled=true
wp wc payment_gateway update cod --user=wp --enabled=truewp admin --user=wpThe plugin is checked against the WordPress Coding Standards with PHP_CodeSniffer. The ruleset lives in phpcs.xml.dist and runs in CI on every pull request.
composer install
composer phpcsAuto-fix what can be fixed automatically with:
composer phpcs:fixPre-existing violations are recorded in phpcs.baseline.xml so they do not fail CI, while new violations do. When you fix a baselined violation, regenerate the baseline so it shrinks over time:
vendor/bin/phpcs --report=\\DR\\CodeSnifferBaseline\\Reports\\Baseline --report-file=phpcs.baseline.xmlThe tests/Integration suite contains characterization tests that pin down the current behaviour of the core flows (shipment payload "golden" tests, rate calculation, order meta accessors on legacy and HPOS storage, label generation with a mocked API, frontend pick-up point display). No refactor PR merges without tests covering the moved behaviour: keep these suites green, and extend them in the same PR for any code you move that is not yet covered. Both CI workflows run on every pull request and on pushes to main and develop.
End-to-end browser tests are written with Pest (backed by Playwright) and run against a store created by the setup script. Locally:
composer install
npm install
npx playwright install chromium
# Set up and start the store (in a separate terminal, keep it running)
bin/setup-local-dev.sh
php -d memory_limit=512M local-dev/wordpress/.wp-cli/wp-cli.phar --path=local-dev/wordpress server --host=127.0.0.1 --port=8181
# Run the tests
composer testThe tests read WP_BASE_URL, WP_ADMIN_USER and WP_ADMIN_PASS from the environment (defaulting to the setup script's defaults: http://127.0.0.1:8181, admin / password). The same flow runs in CI via the Browser Tests workflow, which provisions the store with bin/setup-local-dev.sh on every pull request. Failure screenshots are saved to tests/Browser/Screenshots/ and uploaded as workflow artifacts.
Wordpress Plugin releases are managed by SVN and to sync the plugin to a local folder run:
svn co https://plugins.svn.wordpress.org/smart-send-logistics smart-send-logisticsNote that the following command can be used to check which files are modified/added/deleted:
svn statSimply run the command from within the svn folder to revert all local changes:
svn revert -R .The easiest way to release a new version of the plugin is by running the deploy script in the root of the repository:
sh scripts/svn-deploy.shAlternative do this manually by following these steps:
- Update all mentions of the
Versionin the following files:
smart-send-logistics/smart-send-logistics.php: Headersmart-send-logistics/smart-send-logistics.php: private property$versionsmart-send-logistics/readme.txt: Stable tag-tag
- Add changelog entry in
smart-send-logistics/readme.txt - Copy folder
smart-send-logisticsto thetrunksvn folder - Copy the
trunkfolder content to a new tagged release using the commandsvn cp trunk tags/8.0.0(replace8.0.0with the new version number) - Commit the work using the command
svn ci -m "tagging version 8.0.0"
To create a plugin zip file of a given branch/tag use:
git archive v8.1.0b4 --output="smart-send-shipping-woocommerce-v810b4.zip" "smart-send-logistics"When developing then it can sometimes be relevant to use Smart Send's sandbox environment or a local server. This is done by implementing the following filter:
function smart_send_api_endpoint_callback( $endpoint ) {
if ($endpoint == 'https://app.smartsend.io/api/v1/') {
$endpoint = 'https://app.smartsend.dev/api/v1/';
}
return $endpoint;
}
add_filter( 'smart_send_api_endpoint', 'smart_send_api_endpoint_callback' );An easy way to implement this is using the Code Snippets plugin and select Run snippet everywhere