1. Login to your WordPress admin account (https://wordpress.com/wp-admin/)

2. Download a plugin to run code on your site.

  • Use the Code Snippets plugin
    • In your WordPress admin select Plugins > Add New and then search for Code Snippets
    • Once the plugin is installed, activate the plugin
    • Select Snippets under the Code Snippets plug in
    • Once you are on the settings page of Code Snippet, enable JavaScript snippet only and click edit
    • 5. Once you are in code edit mode, delete all the sample code and then copy and paste the following code: 
/**
 * 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
}
}
}
}
  • *important field. These should be enclosed in single quotes and changed via your campaign information.

    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.

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

  • Download a plugin to run header script on your site. We recommend using Insert Headers and Footers. Install this plugin as outlined above.

  • Once the plugin is downloaded and activated, go to settings and find the plugin settings as shown below.

  • Insert the following code into the Script in Header area and select 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>
  •  Contact ICS customer service with any additional questions.