我想完成 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_ID 和 CUSTOMER_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_ID 和CUSTOMER_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 订单完成页面中插入 Google Merchant Review JS 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
以编程方式将可下载文件添加到 Woocommerce 产品Add programmatically a downloadable file to Woocommerce products(以编程方式将可下载文件添加到 Woocommerce 产品)
获取今天 Woocommerce 中每种产品的总订单数Get today#39;s total orders count for each product in Woocommerce(获取今天 Woocommerce 中每种产品的总订单数)
在 WooCommerce 和电话字段验证问题中添加自定义注Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和电话字段验证问题中添加自定义注册字段
在 Woocommerce 简单产品中添加一个将更改价格的选Add a select field that will change price in Woocommerce simple products(在 Woocommerce 简单产品中添加一个将更改价格的选择字段)
在 WooCommerce 3 中将自定义列添加到管理产品列表Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中将自定义列添加到管理产品列表)
自定义结帐“下订单"按钮输出htmlCustomizing checkout quot;Place Orderquot; button output html(自定义结帐“下订单按钮输出html)