So far this is what i did…and it kind of work out…
If someone want to adjust / clean the code it will be much appreciated ??
use LicenseManagerForWooCommerce\Models\Resources\License as LicenseResourceModel;
use LicenseManagerForWooCommerce\Repositories\Resources\License as LicenseResourceRepository;
defined('ABSPATH') or die('Unauthorized Access');
add_action('woocommerce_order_status_completed', 'send_info_to_api');
$url = 'https://....';
function send_info_to_api ($order_id){
$order = new WC_Order( $order_id );
//Get the customer data
$DataNeworder = array(
'Date commande' => $order->date_completed,
'Numero de commande' => $order_id ,
'Prénom' => $order->billing_first_name ,
'Nom' => $order->billing_last_name ,
'Société' => $order->billing_company ,
'Addresse1' => $order->billing_address_1 ,
'Adresse2' => $order->billing_address_2 ,
'Ville' => $order->billing_city ,
'Date' => $order->billing_state ,
'CodePostal' => $order->billing_postcode ,
'Pays' => $order->billing_country ,
'Email' => $order->billing_email ,
'Telephone' => $order->billing_phone ,
);
//Gets all licenses from an order according to the order_id
$licenses = LicenseResourceRepository::instance()->findAllBy(
array(
'order_id' => $order_id
));
// No license keys? Nothing to do...
if (!$licenses) {
return;
}
foreach ($licenses as $license):
array_push($DataNeworder, $license->getDecryptedLicenseKey());
endforeach;
// $order->add_order_note( implode(" ",$DataNeworder));
file_put_contents('DataOrderBACnetLog.txt', print_r($DataNeworder, true), FILE_APPEND | LOCK_EX);
}
// send to url
wp_remote_post( $url, $DataNeworder );
-
This reply was modified 3 years, 8 months ago by
marcodu.