我想完成 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:我如何在付款后结帐时echo
ORDER_ID
和CUSTOMER_EMAIL
WooCommerce 上的页面?
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模板网!