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.

 

/**
* 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 );

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
  
  
/**
   * 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) ?>;

(
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 ,
 campaignId, publicKey, '99');
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'
})
    </script>
  
<?php
}
    }
  }
}

 

0 Comments

Please sign in to leave a comment.