問題描述
我想完成 Google Merchant Review 代碼要求在結(jié)賬頁面完成的變量:
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 號(hào)
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 填充它,因?yàn)槲抑辉谖靼嘌冷N售
DELIVERY_COUNTRY: I think I can just fill it with ES since I only sell in Spain
ESTIMATED_DELIVERY_DATE:我已經(jīng)有了一個(gè)用來計(jì)算發(fā)貨日期的函數(shù),所以我想我可以在這里使用那個(gè) php 函數(shù).
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.
總而言之,我需要幫助弄清楚如何在結(jié)帳頁面中回顯 ORDER_ID
和 CUSTOMER_EMAIL
,具體地在所述腳本內(nèi)部.我對(duì)如何做到這一點(diǎn)一無所知,因?yàn)槲宜龅囊磺卸紟砹藶?zāi)難性的結(jié)果
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:我如何在付款后結(jié)帳時(shí)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 目標(biāo)轉(zhuǎn)化代碼完成或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');
代碼位于活動(dòng)子主題(或主題)的 functions.php
文件中.或者也可以在任何插件 PHP 文件中.
代碼已經(jīng)過測試并且可以正常工作.
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.
參考:
- 官方文檔莉>
相關(guān)問題
- Woocommerce 在感謝頁面上獲取訂單并傳遞數(shù)據(jù) javascript 代碼段
- Woocommerce:檢查成功購買的是新客戶還是回頭客
希望這有幫助!
這篇關(guān)于如何在 WooCommerce 訂單完成頁面中插入 Google Merchant Review JS 代碼的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!