Advertisement
majeedraza

WooCommerce - Google Review Opt-In

Jan 9th, 2022
925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1. <?php
  2.   // WooCommerce - Google Review Opt-In
  3.   add_action( 'woocommerce_thankyou', 'google_review_opt_in' );
  4.   function google_review_opt_in( $order_id ) {
  5.     $order = wc_get_order( $order_id );
  6.     $datetime_object = $order->get_date_created();
  7.     $datetime_object->modify( '+21 day' );
  8.     $delivery_date = $datetime_object->date( 'Y-m-d' );
  9.     ?>
  10. <script>
  11.   // Google Review Opt-In
  12.   window.renderOptIn = function() {
  13.     window.gapi.load('surveyoptin', function() {
  14.       window.gapi.surveyoptin.render(
  15.         {
  16.           "merchant_id": 9085387,
  17.           "order_id": "<?php echo $order->get_id(); ?>",
  18.           "email": "<?php echo $order->get_billing_email(); ?>",
  19.           "delivery_country": "<?php echo $order->get_billing_country(); ?>",
  20.           "estimated_delivery_date": "<?php echo $delivery_date; ?>",
  21.          });
  22.     });
  23.   }
  24. </script>
  25.    <?php
  26.   } // end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement