Integrating Woocommerce subscriptions is very easy. Follow the steps below to integrate it with OSI Affiliate Software.


Step 1. Add this code to woocommerce thank you page before the </body> tag:


<?php

$order = wc_get_order($order);

$ot = $order->order_total;

$os = $order->order_shipping;

$final = $ot-$os;

$coupons = $order->get_items('coupon');

$PromoCode = '';

foreach($coupons as $coupon) {

    $PromoCode = $coupon['name'];

    break;

}

?>

<script>

function hideIF() {

    document.getElementById('IF').style.display = '';

}


function getSaleInfo() {

    document.getElementById('st_code').innerHTML='<iframe src="https://arlentest2.ositracker.com/sales/salejs/amount:<?php

        echo $final; ?>/transaction:<?php

        echo $order->id ?>/PromoCode:<?php

        echo $PromoCode ?>/customer_email:<?php

        echo $order->get_billing_email() ?>" alt="" id=IF width=50 height=50 border="0" frameborder="0" onload="hideIF()">';

}


window.onload = getSaleInfo;

</script>

<div id="st_code"></div>


Note: Make sure to replace https://arlentest2.ositracker.com with your actual OSI Affiliate Software domain.


Step 2. We need to add these lines in WP theme's functions.php file.


function osi_recurring( $subscription, $order ) {

    $response = wp_remote_get( 'https://aamirshahzad.ositracker.com/sales/send_recurring?key=390db4e976f674cacae20ef0f696c20c&customer_email='.$order->get_billing_email().'&amount='.$order->get_total().'&transaction='.$order->get_order_number() );

}

add_action( 'woocommerce_subscription_renewal_payment_complete', 'osi_recurring', 10, 2 );


Note: Make sure to create your own key and replace 390db4e976f674cacae20ef0f696c20c

Replace https://aamirshahzad.ositracker.com with your actual OSI Affiliate Software domain.


To get your own key, follow the steps below:


Step 1. Login to your OSI Affiliate Software dashboard and click on your profile located at the bottom-left.


Step 2. Select Modify Profile.


Step 3. Copy the API User Token if the field is already filled or click on Regenerate API Key if it's blank.