Skip to content

Instantly share code, notes, and snippets.

@riy
Last active July 13, 2017 23:49
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 riy/42e57d3411b24819f75d7a13709335c2 to your computer and use it in GitHub Desktop.
Save riy/42e57d3411b24819f75d7a13709335c2 to your computer and use it in GitHub Desktop.
WooCommerce Plugin: Order Details on "Thank You" Page As Global JavaScript variables
<?php
/**
* Plugin Name: Order Details on Thank You Page
* Version: 1.0
* Author: Rias A. Sherzad
* Description: This plugin will export some order details on the thank you page as global JavaScript variables, e.g. for accessing them from Google Tag Manager
*/
if (!defined('ABSPATH'))
{
exit;
}
function woo_OrderDetailsOnThankYouPage($order_id)
{
// Load the order
$order = wc_get_order( $order_id );
?>
<script type="text/javascript">
var woo_order_key = '<?= $order->get_order_key() ?>';
var woo_order_currency = '<?= $order->get_data()['currency'] ?>';
var woo_order_total_net = '<?= ($order->get_data()['total'] - $order->get_data()['total_tax']) ?>';
</script>
<?php
}
add_action('woocommerce_thankyou', 'woo_OrderDetailsOnThankYouPage', 10, 1);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment