Skip to content

Instantly share code, notes, and snippets.

@sandeshjangam
Created March 31, 2020 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandeshjangam/7597679c4bc291c3ab36fa7f6073161b to your computer and use it in GitHub Desktop.
Save sandeshjangam/7597679c4bc291c3ab36fa7f6073161b to your computer and use it in GitHub Desktop.
Everflow conversion sample
add_action( 'wp_head', 'ev_add_ev_code_in_head' );
function ev_add_ev_code_in_head(){
global $post;
$head_code = '';
if( 'cartflows_step' === $post->post_type ){
$step_type = get_post_meta( $post->ID, 'wcf-step-type', true );
if ( 'thankyou' === $step_type && isset( $_GET['wcf-order'] ) && ! empty( $_GET['wcf-order'] ) ) {
$order_id = filter_input( INPUT_GET, 'wcf-order', FILTER_SANITIZE_NUMBER_INT );
$order = wc_get_order( $order_id );
//Everflow order objects
$efOrder = array();
$efOrder['items'] = array();
$efOrder['oid'] = $order_id;
$efOrder['amt'] = $order->get_total();
$efOrder['bs'] = $order->get_billing_state();
$efOrder['bc'] = $order->get_billing_country();
// Determine if any coupons were used for this transaction
$coupons = "";
$efOrder['cc'] = $coupons;
// This is how to grab line items from the order
$line_items = $order->get_items();
// This loops over line items
$efItems = array();
foreach ( $line_items as $item ) {
//Init Everflow item
$efItem = array();
// This will be a product
$product = $order->get_product_from_item( $item );
// This is the products SKU (variant or parent)
$efItem['vs'] = '';
$efItem['ps'] = '';
if ( $product->get_type() === 'variation' )
{ $efItem['vs'] = $product->get_sku(); }
else
{ $efItem['ps'] = $product->get_sku(); }
// This is the qty purchased
$efItem['qty'] = $item['qty'];
// Line item total cost including taxes and rounded
$efItem['p'] = $order->get_line_total( $item, true, true );
// Add this to Everflow items
$efItems[] = $efItem;
}
$efOrder['items'] = $efItems;
$amount = $order->get_total();
$head_code = "
<script type='text/javascript'src='https://www.bos88trk.com/scripts/sdk/everflow.js'></script>
<script type='text/javascript'>
EF.conversion({
offer_id: 1,
advid: 1,
amount: " . $amount . ",
order: " . json_encode($efOrder) . ",
});
</script>
";
}
}
echo $head_code;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment