問題描述
我想完成 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 在感謝頁面上獲取訂單并傳遞數據 javascript 代碼段
- Woocommerce:檢查成功購買的是新客戶還是回頭客
希望這有幫助!
這篇關于如何在 WooCommerce 訂單完成頁面中插入 Google Merchant Review JS 代碼的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!