Last active
July 13, 2017 23:49
-
-
Save riy/42e57d3411b24819f75d7a13709335c2 to your computer and use it in GitHub Desktop.
WooCommerce Plugin: Order Details on "Thank You" Page As Global JavaScript variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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