Last active
May 26, 2020 12:50
-
-
Save sarangs07/85140b5cee39d9a704b9ca4c4a52522e to your computer and use it in GitHub Desktop.
Add Event snippet for [HB] Compra General conversion page
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
/* | |
* How to add the custome code. | |
* | |
* Please follow below instructions: | |
* 1. Copy the below code. | |
* 2. Open your child theme's functions.php file. | |
* 3. Paste the copied code at the very bottom of it & save the file OR upload it on your server/hosting. | |
*/ | |
add_action( 'wp_head', 'pp_add_event_code_in_head' ); | |
function pp_add_event_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 ); | |
$amount = $order->get_total(); | |
$head_code = " | |
<!-- Event snippet for [HB] Compra General conversion page --> | |
<script> | |
gtag('event', 'conversion', { | |
'send_to': 'AW-813381707/NCcqCIzr5s0BEMvw7IMD', | |
'value': {{ ". $amount ." }}, | |
'currency': EUR', | |
'transaction_id': '{{ ". $order_id ." }}' | |
}); | |
</script> | |
"; | |
} | |
} | |
echo $head_code; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment