What I want to do is seemingly very easy, and I’m sure I’m missing one very obvious, very simple step for seasoned developers, but I’m very much a self-taught, trial and error kind of guy. So, here’s what I’m trying to do….
My client has a bunch of custom fields that get added to each WooCommerce order; however, the native plugin doesn’t allow us to pass them into the event data. I’m trying to create a second event that gets triggered whenever there’s a new order and pass those extra fields in as their own event.
I’m following the PHP code example found here in the Track API doc, and hooking into the WooCommerce New order action. My current code, which does not work, looks like this:
add_action( 'woocommerce_new_order', 'lgs_custom_klaviyo_event', 1, 2 );
function lgs_custom_klaviyo_event( $order_id, $order ) {
require_once('vendor/autoload.php');
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://a.klaviyo.com/api/track', [
'form_params' => [
'data' => '{"token": "MY_API", "event": "Love Jar Purchase", "customer_properties": {"$email": "MY_EMAIL"}, "properties": {"$event_id": $order_id,"Jar recipient": "Tovita","$value": 100}}'
],
'headers' => [
'Accept' => 'text/html',
'Content-Type' => 'application/x-www-form-urlencoded',
],
]);
echo $response->getBody();
};
The WooCommerce error log states this:
CRITICAL require_once(): Failed opening required 'vendor/autoload.php' (include_path='.:/usr/share/php') in /www/wp-content/themes/custom-child-theme/functions.php on line 476
Which corresponds to the line of code: require_once(‘vendor/autoload.php’);
From what I gather, it has something to do with this little message above the code example on the Track API page:

I’ve tried searching and figuring out how and where and what the composer is or how and where to install it, but I don’t even know if that’s the thing I need to be chasing down.
Anyways, once I can send this tiny little test packet, figuring out the actual JSON payload for the custom fields is the easy part.
Then again, maybe I’m way off base and need a lot more help than I think. heh
Thank you!