因此,我在实施自定义跟踪代码时遇到问题,该代码会提取订单信息。
到目前为止,我在我的functions.php文件中找到了什么,但是当我进行购买时,它实际上并没有显示任何信息。
add_action( 'woocommerce_thankyou', 'conversion_tracking' );
function conversion_tracking() {
$order = wc_get_order( $order_id );
$order_id = $order->get_id;
$order_parent_id = $order->get_parent_id;
$order_status = $order->get_status;
$order_currency = $order->get_currency;
$order_version = $order->get_version;
$order_payment_method = $order->get_payment_method;
$order_payment_method_title = $order->get_payment_method_title;
$order_payment_method = $order->get_payment_method;
$order_payment_method = $order->get_payment_method;
?>
<script type = 'text/javascript'>
window.sovIframes = window.sovIframes || [];
window.sovIframes.push({
trafficSourceNumber : '',
trafficMediumNumber : '',
timestamp : '<?php echo $order_timestamp_created ?>',
orderId : '<?php echo $order_id ?>',
orderValue : '<?php echo $order_total ?>',
orderCurrency : '<?php echo $order_currency ?>',
});
<?php
}
当我尝试使用此代码提取订单数据时:
$order = wc_get_order( $order_id );
$order_data = $order->get_data();
$order_id = $order_data['id'];
$order_parent_id = $order_data['parent_id'];
$order_status = $order_data['status'];
$order_currency = $order_data['currency'];
$order_version = $order_data['version'];
$order_payment_method = $order_data['payment_method'];
$order_payment_method_title = $order_data['payment_method_title'];
$order_payment_method = $order_data['payment_method'];
$order_payment_method = $order_data['payment_method'];
我收到以下错误:
致命错误:未捕获错误:调用成员函数get_data() 布尔值 /home/feratino/www/REMOVED/wp-content/themes/REMOVED/functions.php:28 堆栈跟踪:0 /home/feratino/www/REMOVED/wp-includes/class-wp-hook.php(298): sovendus_conversion_tracking(109947)
1 /home/REMOVED/wp-includes/class-wp-hook.php(323): WP_Hook-&gt; apply_filters(NULL,Array)
2 /home/feratino/www/REMOVED/wp-includes/plugin.php(453): WP_Hook-&gt; do_action(数组)
3 /home/feratino/www/REMOVED/wp-content/plugins/woocommerce/templates/checkout/thankyou.php(74): do_action(&#39; woocommerce_tha ...&#39;,109947)
4 /home/feratino/www/REMOVED/wp-content/plugins/woocommerce/includes/wc-core-functions.php(204): 包括(&#39; / home / feratino /... 39;)
5 /home/feratino/www/REMOVED/wp-content/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-checkout.php(205): wc_get_template(&#39; checkout / thanky ...&#39;,数组)
6 /家庭/ feratino / WWW /删除/可湿性粉剂内容/插件/ woocommerce /包括/简码/类-WC-S 在 /home/feratino/www/REMOVED/wp-content/themes/REMOVED/functions.php 在第28行
我的functions.php中的第28行:
$order_data = $order->get_data();
答案 0 :(得分:0)
请尝试此代码
add_action( 'woocommerce_thankyou', 'conversion_tracking' );
function conversion_tracking($order_id ) {
// Lets grab the order
$order = new WC_Order( $order_id );
// Order ID
$order_id = $order->get_order_number();
// Order total
$order_total = $order->get_total();
// Order e-mail
$order_email = $order->billing_email;
...
...