【问题标题】:Custom Woocommerce Tracking Pixel Not Pulling Values自定义 Woocommerce 跟踪像素不提取值
【发布时间】:2021-09-09 17:41:12
【问题描述】:

我正在为 woocommerce 添加一个跟踪像素,并希望提取订单 ID 和订单值以通过他们的像素发布到第 3 方数据库。我可以在感谢页面上很好地获取像素读数,但是订单 ID 和订单值的值没有输入,并且在 url 字符串中输出。我刚刚将像素更新为:

//Tracking pixel for Funker360
add_action( 'woocommerce_thankyou', 'funker360_pixel' );
function funker360_pixel($order_id) {
    $order = wc_get_order($order_id);
    $order_total = $order->get_total();
    echo( "<img style='display:none;’ src=\"https://urlinfoforpixel&Order_Id=$order&total=$order_total\">");
}

我的最后一次迭代:

//Tracking pixel for Funker360
add_action( 'woocommerce_thankyou', 'funker360_pixel' );
function funker360_pixel($order_id) {
    $order = wc_get_order($order_id);
    $order_total = $order->get_total();
    echo( "<img style='display:none;’ src=\"https://urlinfoforpixel&Order_Id={$order}&total={$order_total}\">");
}

任何关于如何获取订单 ID 和订单价值并将它们添加到字符串的帮助或输入将不胜感激,我觉得它很接近。我刚刚将 printif 更新为 echo,并且该值没有通过 printif 输出。

【问题讨论】:

    标签: php woocommerce pixel


    【解决方案1】:
    echo "<img style='display:none' src='https://blabla&Order_Id=" . $order->get_id() . "&total=" . $order->get_total() . "'>";
    

    我已经对 PHP 进行了一些清理以避免单引号和双引号出现问题。另外,$order->get_id() 会为你计算订单 ID

    【讨论】:

    • 嗨businessbloomer,你能用一句话解释这段代码的作用吗? (这很明显,但仅代码的答案通常被算法标记为低质量。添加一个简短的解释通常可以防止这种情况发生。
    • 会的,抱歉
    • 现在添加了一些上下文
    • 谢谢,解决了将变量导入数据库的问题!
    • 太棒了!有时间请采纳答案:meta.stackexchange.com/questions/5234/…
    猜你喜欢
    • 1970-01-01
    • 2014-09-12
    • 2015-10-07
    • 2014-10-24
    • 1970-01-01
    • 1970-01-01
    • 2018-03-12
    • 2017-10-14
    • 1970-01-01
    相关资源
    最近更新 更多