Skip to content

Instantly share code, notes, and snippets.

@thommeredith
Created June 8, 2017 18:33
Show Gist options
  • Save thommeredith/97922fba396c7a64b2c2772058f8c872 to your computer and use it in GitHub Desktop.
Save thommeredith/97922fba396c7a64b2c2772058f8c872 to your computer and use it in GitHub Desktop.
Referral Candy WooCommerce Order Confirmation Popup
add_action( 'woocommerce_thankyou', 'refcandy_lollipop' );
function refcandy_lollipop( $order_id ) {
$order = wc_get_order( $order_id );
$divData = [
'id' => 'refcandy-lollipop',
'data-id' => 'USEYOURIDFROMYOURACCOUNT',
'data-fname' => $order->billing_first_name,
'data-lname' => $order->billing_last_name,
'data-email' => $order->billing_email,
];
$div = '<div '.implode(' ', array_map(function ($v, $k) { return $k . '="'.addslashes($v).'"'; }, $divData, array_keys($divData))).'></div>';
$script = '<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//portal.referralcandy.com/assets/widgets/refcandy-lollipop.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","refcandy-lollipop-js");</script>';
echo $div.$script;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment