0

How can I add this third-party script to the Woocommerce thank you page that requires some customer data to be populated:

<script type="text/javascript">
lr(function(){
    var customerEmail = '{customer_email}';
    if (customerEmail.includes("@")) {
        REFERSION.box.show({
            loc : 'https://www.refersion.com/channels/post_purchase/v2',
            code : '2bf89afa29',
            customer_first_name : encodeURIComponent('{customer_first_name}'),
            customer_last_name : encodeURIComponent('{customer_last_name}'),
            customer_email : encodeURIComponent('{customer_email}')
        });
    }
});
function lr(e){var t=document.createElement("script");t.type="text/javascript";if(t.readyState){t.onreadystatechange=function(){if(t.readyState=="loaded"||t.readyState=="complete"){t.onreadystatechange=null;e()}}}else{t.onload=function(){e()}}t.src="https://www.refersion.com/channels/post_purchase/v2/js";document.body.appendChild(t)}
</script>
mujuonly
  • 11,370
  • 5
  • 45
  • 75
system0102
  • 129
  • 2
  • 5

1 Answers1

1
add_action('woocommerce_before_thankyou', 'woocommerce_before_thankyou', 10 , 1);

function woocommerce_before_thankyou( $order_id ) {

            $order = wc_get_order( $order_id );
            echo "
<script type='text/javascript'>
lr(function(){
    var customerEmail = '{$order->get_billing_email()}';
    if (customerEmail.includes('@')) {
        REFERSION.box.show({
            loc : 'https://www.refersion.com/channels/post_purchase/v2',
            code : '2bf89afa29',
            customer_first_name : encodeURIComponent('{$order->get_billing_first_name()}'),
            customer_last_name : encodeURIComponent('{$order->get_billing_last_name()}'),
            customer_email : encodeURIComponent('{$order->get_billing_email()}')
        });
    }
});
function lr(e){var t=document.createElement('script');t.type='text/javascript';if(t.readyState){t.onreadystatechange=function(){if(t.readyState=='loaded'||t.readyState=='complete'){t.onreadystatechange=null;e()}}}else{t.onload=function(){e()}}t.src='https://www.refersion.com/channels/post_purchase/v2/js';document.body.appendChild(t)}
</script>
";
        }

Exactly what you are looking for.

enter image description here

mujuonly
  • 11,370
  • 5
  • 45
  • 75