WooCommerce powers more than 33% of all ecommerce websites worldwide. That is 4.5 million live stores, the vast majority of them running on WordPress with a developer or agency in the picture. If you build or manage a WooCommerce store and you want to add verified tree planting to every order, this guide explains exactly how to do it.
There is no native WooCommerce plugin from GoodAPI, but there does not need to be. GoodAPI’s REST API works with any platform that can make an HTTP request, and WordPress makes this particularly straightforward using action hooks. You can have a working integration in an afternoon.
Why WooCommerce Stores Are Adding Tree Planting
For WooCommerce merchants, the opportunity is real: adding a tree planting action to your checkout flow costs less than $0.43 per order and gives customers something they can see, verify, and share.
The challenge has always been doing it in a way that holds up to scrutiny. “We plant a tree with every order” is a claim customers are getting more skeptical about. The ones that work are backed by real verification: geolocated trees, named planting organizations, survival data. That is what separates impact you can market from impact you have to qualify in the fine print.
GoodAPI partners with Veritree, a verified reforestation organization with global projects. Every tree planted through GoodAPI is tracked, geolocated, and supported through its critical first years of growth, the period when seedling survival rates matter most.
What You Need Before You Start
To follow this guide, you need:
- A WooCommerce store running on WordPress
- A GoodAPI account with an API key (grab one at thegoodapi.com)
- Basic familiarity with WordPress plugin development or the ability to edit your theme’s functions.php file (though a custom plugin is strongly preferred)
- PHP 7.4 or later
GoodAPI provides two API keys from day one: a test key and a production key. The test key lets you fire real API requests, see responses, and verify your integration without any trees being planted or any charges occurring. Use it throughout development, then switch to the production key when you are ready to go live.
How the Integration Works
The integration pattern is simple. When WooCommerce marks an order as complete, a PHP action fires. Your code listens for that action, reads the order details, and sends a POST request to GoodAPI’s tree planting endpoint. GoodAPI handles everything from that point: routing the request to a verified planting project, recording the impact data, and making the results available in your dashboard.
The GoodAPI endpoint you will use is:
POST https://app.thegoodapi.com/plant/treesAuthorization: YOUR_API_KEYContent-Type: application/jsonThe request body:
{ "count": 1, "metadata": { "order_id": "WC-12345", "customer_email": "customer@example.com", "source": "woocommerce" }}The metadata fields are optional but worth including. They let you correlate every tree planting event with a specific order in your WooCommerce dashboard, which makes reporting and customer-facing impact summaries much easier to build.
Step-by-Step: Building the WooCommerce Integration
Step 1: Create a Custom Plugin
Do not add this code to functions.php. Use a custom plugin instead. This keeps your integration intact during theme updates and makes it easier to manage API key configuration.
Create a new directory at wp-content/plugins/goodapi-woocommerce/ and add a file called goodapi-woocommerce.php:
<?php/** * Plugin Name: GoodAPI Tree Planting for WooCommerce * Description: Plants trees via GoodAPI when WooCommerce orders complete. * Version: 1.0.0 */
if ( ! defined( 'ABSPATH' ) ) { exit;}
// Plant trees when an order status changes to 'completed'add_action( 'woocommerce_order_status_completed', 'goodapi_plant_trees_on_order', 10, 1 );
function goodapi_plant_trees_on_order( $order_id ) { $api_key = defined( 'GOODAPI_KEY' ) ? GOODAPI_KEY : get_option( 'goodapi_api_key' );
if ( empty( $api_key ) ) { error_log( 'GoodAPI: API key not configured.' ); return; }
$order = wc_get_order( $order_id ); if ( ! $order ) { return; }
$payload = wp_json_encode( [ 'count' => 1, 'metadata' => [ 'order_id' => (string) $order_id, 'customer_email' => $order->get_billing_email(), 'source' => 'woocommerce', ], ] );
$response = wp_remote_post( 'https://app.thegoodapi.com/plant/trees', [ 'headers' => [ 'Authorization' => $api_key, 'Content-Type' => 'application/json', ], 'body' => $payload, 'timeout' => 15, ] );
if ( is_wp_error( $response ) ) { error_log( 'GoodAPI: Request failed — ' . $response->get_error_message() ); return; }
$status_code = wp_remote_retrieve_response_code( $response ); if ( $status_code !== 200 && $status_code !== 201 ) { error_log( 'GoodAPI: Unexpected status ' . $status_code . ' for order ' . $order_id ); return; }
$body = json_decode( wp_remote_retrieve_body( $response ), true ); if ( ! empty( $body['tree_details'][0]['id'] ) ) { update_post_meta( $order_id, '_goodapi_tree_id', sanitize_text_field( $body['tree_details'][0]['id'] ) ); $order->add_order_note( 'GoodAPI: 1 tree planted. Reference: ' . $body['tree_details'][0]['id'] ); }}Step 2: Store Your API Key
The cleanest way to store the API key is in wp-config.php as a constant, away from the database:
define( 'GOODAPI_KEY', 'your_test_or_production_key_here' );During development, use your test key. When you are ready to go live, swap it for your production key. Because you are using wp-config.php, the key is never stored in the database or exposed via the WordPress admin.
Step 3: Activate and Test
Activate the plugin in the WordPress admin under Plugins. Then place a test order in WooCommerce and mark it as complete manually via the Orders screen. Check your debug log at wp-content/debug.log (make sure WP_DEBUG_LOG is enabled in wp-config.php) to confirm the API call fired and returned a success response.
You can also verify the integration by logging into your GoodAPI dashboard at app.thegoodapi.com, where test tree planting events appear in real time.
Scaling the Integration: More Trees Per Order
The basic integration plants one tree per completed order. You can adjust the quantity based on order value, product category, or any other WooCommerce data you have access to.
For example, to plant one tree per $25 spent:
$order_total = floatval( $order->get_total() );$count = max( 1, intval( $order_total / 25 ) );Or to plant an additional tree for orders that include a specific product category:
$count = 1;foreach ( $order->get_items() as $item ) { $product_id = $item->get_product_id(); if ( has_term( 'sustainable-goods', 'product_cat', $product_id ) ) { $count += 1; break; }}These kinds of rules let you build a more nuanced impact proposition. Orders over a threshold get more trees. Specific products trigger additional actions. The logic is all in your PHP, not in any external configuration.
Showing Customers Their Impact
To add a simple impact message to the WooCommerce order confirmation email:
add_action( 'woocommerce_email_order_meta', 'goodapi_add_impact_to_email', 10, 3 );
function goodapi_add_impact_to_email( $order, $sent_to_admin, $plain_text ) { $tree_id = get_post_meta( $order->get_id(), '_goodapi_tree_id', true ); if ( ! $tree_id ) { return; }
if ( $plain_text ) { echo "\n\nThank you for your order. We planted a tree on your behalf, verified through Veritree.\n\n"; } else { echo '<p><strong>Your impact:</strong> We planted a tree on your behalf, verified through Veritree. Your trees are tracked, geolocated, and cared for through their first years of growth.</p>'; }}This small addition turns the order confirmation email into a moment of genuine connection with your environmental commitment.
Pricing and What to Expect
GoodAPI costs $0.43 per tree with no upfront payment and monthly invoicing. For a WooCommerce store processing 200 orders per month, the total impact cost is around $86 per month . There are no credit bundles to buy in advance and no minimum commitments.
To keep costs predictable, you can track your running total in the GoodAPI dashboard and set internal alerts if volume spikes unexpectedly, for example, during a flash sale or promotional period.
WooCommerce vs. Shopify: Understanding the Difference
If you have worked with GoodAPI on Shopify, the WooCommerce experience is somewhat different. On Shopify, the GoodAPI app handles everything through a native integration. You install the app, configure your rules, and the integration is live in under two minutes.
On WooCommerce, the integration is custom-built on top of the REST API. You have more flexibility, but you are also responsible for the code, the testing, and any edge cases your specific store introduces. For most WooCommerce developers, this is a comfortable tradeoff.
If your business runs on multiple platforms, say Shopify for your main store and a WooCommerce instance for a different region or brand, you can connect both to the same GoodAPI account. All your tree planting activity appears in a single dashboard, and your cumulative impact data stays unified.
Compliance and Verification
Getting Started
The full GoodAPI API reference is at thegoodapi.com/docs/api. You can create an account and grab your test key in a few minutes with no credit card required.
For Shopify merchants who are also managing a WooCommerce store, the GoodAPI app at apps.shopify.com/tree-planting covers the Shopify side with no code required.
If you have questions about the integration or want to talk through a specific use case, the GoodAPI team is reachable at mirvise@thegoodapi.com. Most questions about custom WooCommerce setups can be answered quickly.
WooCommerce gives you the flexibility to build exactly the integration you need. GoodAPI gives you the verified impact to back up what you are building. The combination is straightforward, and the results are something your customers can actually see.