• Hi,

    First of all, thank you for your great plugin.

    I’m very bad in developing and I’m facing some difficulties…
    I need to do 2 things…but let’s start with my first problem.

    I want to send the order info + licence key to a third API.

    I use add_action(‘woocommerce_order_status_completed’, ‘send_info_to_api’);
    I succeed to gather and send the info from WOOCOMMERCE but I need to get the key licence associated to each product.

    I have tried different things but it doesn’t work or maybe I forget to define some things.

    You probably already have the code to achieve that ?

    Thank you very much for your support.

Viewing 1 replies (of 1 total)
  • Thread Starter marcodu

    (@marcodu)

    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.
Viewing 1 replies (of 1 total)
  • The topic ‘Order info + licence key to a third API’ is closed to new replies.