Created
January 17, 2021 09:02
-
-
Save davevanhoorn/22cac2d1f199e0565b11fff82986b4ad to your computer and use it in GitHub Desktop.
WooCommerce action thankyou.php and functions.php
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
/** | |
* file: functions.php | |
* Update meta data when someone's looking at their order thank you page | |
*/ | |
function thank_you_page( $order_id ){ | |
$order = wc_get_order($order_id); | |
$order->update_meta_data('_user_has_loaded_thank_you_page', 'yes'); | |
$order->save(); | |
} | |
add_action( 'woocommerce_thankyou', __NAMESPACE__ . '\\thank_you_page', 10, 1); | |
/** | |
* file: thankyou.php | |
* Push to the dataLayer only when order meta data is not "yes" | |
*/ | |
<?php if ('yes' !== get_post_meta($order->get_id(), '_user_has_loaded_thank_you_page', true)) { ?> | |
<script> | |
window.dataLayer = window.dataLayer || []; | |
........ | |
</script> | |
<?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment