如何在 WooCommerce 订单完成页面中插入 Google Merchant Review JS 代码

2023-01-17php开发问题
23

本文介绍了如何在 WooCommerce 订单完成页面中插入 Google Merchant Review JS 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想完成 Google Merchant Review 代码要求在结账页面完成的变量:

I want to complete the variables the Google Merchant Review codes asks to be completed on the checkout page:

<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(
        {
          "merchant_id": mymerchantid,
          "order_id": "ORDER_ID",
          "email": "CUSTOMER_EMAIL",
          "delivery_country": "COUNTRY_CODE",
          "estimated_delivery_date": "YYYY-MM-DD"
        });
    });
  }
</script>

我需要echo以下变量:

ORDER_ID:WooCommerce 订单 ID 的 ID 号

ORDER_ID: ID number of the WooCommerce order ID

CUSTOMER_EMAIL:订单的客户信息部分中列出的电子邮件

CUSTOMER_EMAIL: The email listed in the customer information section of the order

DELIVERY_COUNTRY:我想我可以用 ES 填充它,因为我只在西班牙销售

DELIVERY_COUNTRY: I think I can just fill it with ES since I only sell in Spain

ESTIMATED_DELIVERY_DATE:我已经有了一个用来计算发货日期的函数,所以我想我可以在这里使用那个 php 函数.

ESTIMATED_DELIVERY_DATE: I already have a function I use to calculate the shipping date, so I guess I can use that php function here.

总而言之,我需要帮助弄清楚如何在结帐页面中回显 ORDER_IDCUSTOMER_EMAIL,具体地在所述脚本内部.我对如何做到这一点一无所知,因为我所做的一切都带来了灾难性的结果

In conclusion, I would need help figuring out how do I echo the ORDER_ID and CUSTOMER_EMAIL in the checkout page, concretely inside of said script. I'm kind of clueless on how to do so, since all I tried had kind of a catastrophic result

非常感谢您的阅读!

TL;DR:我如何在付款后结帐时echoORDER_IDCUSTOMER_EMAILWooCommerce 上的页面?

TL;DR: How do I get to echo the ORDER_ID and CUSTOMER_EMAIL in the after payment checkout page on WooCommerce?

推荐答案

如果您想在订单中添加 JavaScript 目标转化代码完成或Thankyou页面然后你必须使用woocommerce_thankyou 钩子.

代码如下:

function wh_CustomReadOrder($order_id) {
    //getting order object
    $order = wc_get_order($order_id);
    $email = $order->billing_email;
    ?>
    <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(
                        {
                            "merchant_id": mymerchantid,
                            "order_id": "<?php echo $order_id; ?>",
                            "email": "<?php echo $email; ?>",
                            "delivery_country": "COUNTRY_CODE",
                            "estimated_delivery_date": "YYYY-MM-DD"
                        }
                );
            });
        };
    </script>
    <?php
}

add_action('woocommerce_thankyou', 'wh_CustomReadOrder');

代码位于活动子主题(或主题)的 functions.php 文件中.或者也可以在任何插件 PHP 文件中.
代码已经过测试并且可以正常工作.

Code goes in functions.php file of your active child theme (or theme). Or also in any plugin PHP files.
Code is tested and works.

参考:

  • 官方文档

相关问题

  • Woocommerce 在感谢页面上获取订单并传递数据 javascript 代码段
  • Woocommerce:检查成功购买的是新客户还是回头客

希望这有帮助!

这篇关于如何在 WooCommerce 订单完成页面中插入 Google Merchant Review JS 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17