function qreuz_google_customer_reviews_optin( $order_id ) {
$order = new WC_Order( $order_id );
?>
<script src=”https://apis.google.com/js/platform.js?onload=renderOptIn” async defer></script>
<script>
window.renderOptIn = function() {
window.gapi.load(‘surveyoptin’, function() {
window.gapi.surveyoptin.render(
{
// REQUIRED FIELDS
“merchant_id”: 103068797, // place your merchant ID here, get it from your Merchant Center at https://merchants.google.com/mc/merchantdashboard
“order_id”: “<?php echo esc_attr( $order->get_order_number() ); ?>”,
“email”: “<?php echo esc_attr( $order->get_billing_email() ); ?>”,
“delivery_country”: “<?php echo esc_attr( $order->get_billing_country() ); ?>”,
“estimated_delivery_date”: “<?php echo esc_attr( date( ‘Y-m-d’, strtotime( ‘+5 day’, strtotime( $order->get_date_created() ) ) ) ); ?>”, // replace “5 day” with the estimated delivery time of your orders
“opt_in_style”: “CENTER_DIALOG”
});
});
}</script>
<?php
}
add_action( ‘woocommerce_thankyou’, ‘qreuz_google_customer_reviews_optin’ );