WooTrain/wootrain/wootrain.php

47 lines
1.1 KiB
PHP
Raw Normal View History

2021-03-24 19:30:01 +00:00
<?php
/**
* Plugin Name: Wootrain
* Plugin URI: autonomic.zone
* Description: woocommerce -> wootrain link
* Author: trav n calix
* Text Domain: wootrain
* Domain Path: /languages
* Version: 0.1.0
* @package Wootrain
*/
add_action( 'woocommerce_thankyou', 'my_api_call');
function my_api_call( $order_id ){
// Order Setup Via WooCommerce
$order = new WC_Order( $order_id );
// if they want to receive the newsletter
if (get_post_meta( $order->id, 'newsletter_', "No")== "Yes"){
//get the email
$email = $order->billing_email;
// build API payload
$url = '[your mailtrain URL here]/api/subscribe/[your mailtrain list ID here]?access_token=[your mailtrain API key here]';
$body = array(
'EMAIL' => $email,
'FORCE_SUBSCRIBE' => "yes"
);
//Call the API
$response = wp_remote_post( $url,
array(
'headers' => array('Content-Type' => 'application/json; charset=utf-8'),
'method' => 'POST',
'timeout' => 75,
'body' => json_encode($body),
)
);
//see if the response was good
//$vars = json_decode($response['body'],true);
}
}