Google Customer Reviews in 'woocommerce_thankyou' action not working

#1
I added the code below to my theme's function.php. But when lscache plugin is active, the code below not working. But when I deactivate the plugin, it works.

I am waiting for your help.

function qreuz_google_customer_reviews_optin( $order_id ) {
$order = new WC_Order( $order_id );
$qreuz_google_customer_reviews_opt_in_script_js = '<script src="https://apis.google.com/js/platform.js?onload=renderOptIn" async defer></script>';
echo $qreuz_google_customer_reviews_opt_in_script_js;
$qreuz_google_customer_reviews_opt_in_script = '
window.renderOptIn = function() {
window.gapi.load(\'surveyoptin\', function() {
window.gapi.surveyoptin.render(
{
// REQUIRED FIELDS
"merchant_id": ********, // place your merchant ID here, get it from your Merchant Center at https://merchants.google.com/mc/merchantdashboard
"order_id": "' . $order->get_order_number() . '",
"email": "' . $order->get_billing_email() . '",
"delivery_country": "' . $order->get_billing_country() . '",
"estimated_delivery_date": "' . 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"
});
});
}';
wp_register_script( 'qreuz_google_customer_reviews_opt_in_script', '', '', 'false', 'true' );
wp_enqueue_script( 'qreuz_google_customer_reviews_opt_in_script' );
wp_add_inline_script( 'qreuz_google_customer_reviews_opt_in_script', $qreuz_google_customer_reviews_opt_in_script );
}
add_action( 'woocommerce_thankyou', 'qreuz_google_customer_reviews_optin');
 
Top