Support Center

Follow

ICS: WooCommerce Integration Instructions

1. Log in to your WordPress admin account.

2. Download a plugin to run code on your site. We recommend using Code Snippets.

3. Once your plugin is installed, make sure that your code plugin is activated and add the ICS script by clicking on Snippets

4. Once you are on the setting page of Code Snippet, enable JavaScript snippet only and click edit.

5. Once you are in code edit mode, delete all sample code then copy and paste the following code. See “ICS Quickstart Guide” for more information on how to customize ICS script further. Note that orderId, email, and revenue are required fields.

*important field. These should be enclosed in single quotes
campaignId - This number should match the campaignId on ICS admin. If you want to run a different campaign on order confirmation, you should change this value. 
publicKey - You should be able to access your public key in your campaign setting page. See below. 


1.png

 

/**

 * This is a PHP code, so should be wrapped inside PHP

 * Like we added here.

 * If PHP is already open then don't include above <?php open tag

 */

/**

 * Adding custom javascripts or php action on WooCommerce Thank you page

 * Works with WooCommerce 3.0 or above

 */

add_action( "woocommerce_thankyou", "xlwcty_thank_you_script", 20 );




function debug_to_console($data, $context = 'Debug in Console') {




    // Buffering to solve problems frameworks, like header() in this and not a solid return.

    ob_start();




    $output  = 'console.info(\'' . $context . ':\');';

    $output .= 'console.log(' . json_encode($data) . ');';

    $output  = sprintf('<script>%s</script>', $output);




    echo $output;

}





if ( ! function_exists( 'xlwcty_thank_you_script' ) ) {

function xlwcty_thank_you_script( $order_id ) {

if ( $order_id > 0 ) {

$order = wc_get_order( $order_id );

if ( $order instanceof WC_Order ) {

$order_id               = $order->get_id(); // order id

$order_key              = $order->get_order_key(); // order key

$order_total            = $order->get_total(); // order total

$order_email            = $order->get_billing_email(); // order email

$order_first_name       = $order->get_billing_first_name(); // order first name

$order_last_name        = $order->get_billing_last_name(); // order last name

$order_currency         = $order->get_currency(); // order currency

$order_payment_method   = $order->get_payment_method(); // order payment method

$order_shipping_country = $order->get_shipping_country(); // order shipping country

$order_billing_country  = $order->get_billing_country(); // order billing country

$order_status           = $order->get_status(); // order status

$order_transactionid    = $order->get_transaction_id(); // order status

/**

* full list methods and property that can be accessed from $order object

* https://docs.woocommerce.com/wc-apidocs/class-WC_Order.html

*/




?>

                    <script type="text/javascript">

var order_id = <?php echo json_encode($order_id) ?>;

var order_email = <?php echo json_encode($order_email) ?>;

var order_total = <?php echo json_encode($order_total) ?>;

var order_first_name = <?php echo json_encode($order_first_name) ?>;

var order_last_name = <?php echo json_encode($order_last_name) ?>;

var order_transactionid = <?php echo json_encode($order_transactionid) ?>;

(function(i,s,r,publicKey,campaignId,a,m,frame,bodyChild){  

i['IceCreamSocialObject'] = r;  

i[r] = i[r] || function(){( i[r].q = i[r].q||[]).push(arguments)}, i[r].l = +new Date();  

a = s.createElement('script'), m = s.scripts[0];  

a.async = a.src = 'https://app.icecreamsocial.io/js/ics.js';  

m.parentNode.insertBefore(a,m);  

frame = s.createElement('iframe'), bodyChild = s.body.firstChild;  

frame.src = 'https://app.icecreamsocial.io/?campaignId='+campaignId+'&publicKey='+publicKey;  

frame.id='SocialIframe', frame.style.cssText = 'position:fixed;height:0%;width:0%;z-index:9999;border: 0';

bodyChild.parentNode.insertBefore(frame,bodyChild);})(window ,document ,'ics', 'publicKey', 'campaignId');

ics('addTransaction', {  

orderId: order_id,  

email: order_email,  

revenue: order_total,

// the following items are optional

name: order_first_name + ' ' + order_last_name,

locale: 'en'

// the following fields are optional if you use Cliq as Payment Gateway

transactionId: order_transactionid,

     transactionGateway: 'CardFlex',

})

</script>

<?php

}

}

}

}

6. Note that orderId, email, and revenue are required fields. 

7. Download a plugin to run header script on your site. We recommend using Insert Headers and Footers. 

8. Once the plugin is downloaded and activated, go to setting and find the plugin setting as shown below.
2.png

9. Insert the following code as “Script in Header”  and save.

<script>

    function setICSCookies(){

      var ICSRegex = /invite=([a-zA-Z0-9%]+)/;

      var queryString = location.search;

      var ICSQueryString = queryString.match(ICSRegex);

      if (ICSQueryString) {

        document.cookie = 'invite=' + ICSQueryString[ICSQueryString.length - 1] +'; Max-Age=30000000;' + 'Path=/';  

      }

    }

    setICSCookies();

</script>

 

10. Contact ICS customer service for additional questions. 

 

0 Comments

Please sign in to leave a comment.