woocommerce_new_order操作未返回所有订单详细信息 [英] woocommerce_new_order action not returning all order details

查看:63
本文介绍了woocommerce_new_order操作未返回所有订单详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 woocommerce_new_order 操作将订单详细信息发送到Mailchimp列表.

I'm using the woocommerce_new_order action to send order details to a Mailchimp list.

// Add user to mailchimp list
function add_user_to_mailchimp($order_id) {
    $order = get_post_meta($order_id);

    write_log($order);

}
add_action( 'woocommerce_new_order', 'add_user_to_mailchimp', 1, 1 );

要记住的重要部分是用户不一定注册帐户.

An important part to keep in mind is that the user may not necessarily register an account.

最重要的部分是检索客户的电子邮件,并将其发送到Mailchimp.我想通过使用

The most important part is retrieving the the customers email and sending that through to Mailchimp. I want to achieve this by using

get_post_meta($order_id, 'billing_email', true);

但是即使我使用'_billing_email',它也会返回一个空值.

but this returns an empty value even if I use '_billing_email'.

当我在日志中输出$ order时,得到以下输出:

When I output the $order in the log I get the following output:

[17-Jan-2017 07:47:35 UTC] Array
(
     [_wc_customer_order_csv_export_is_exported] => Array
        (
            [0] => 0
        )

    [_wc_customer_order_csv_export_customer_is_exported] => Array
        (
            [0] => 0
        )

    [_order_key] => Array
        (
            [0] => wc_order_587dcc17ca5f0
        )

    [_order_currency] => Array
        (
            [0] => ZAR
        )

    [_prices_include_tax] => Array
        (
            [0] => yes
        )

    [_customer_ip_address] => Array
        (
            [0] => ::1
        )

    [_customer_user_agent] => Array
        (
            [0] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:50.0) Gecko/20100101 Firefox/50.0
        )

    [_customer_user] => Array
        (
            [0] => 0
        )

    [_created_via] => Array
        (
            [0] => checkout
        )

    [_cart_hash] => Array
        (
            [0] => 4457fd575a37c07e4863ce5610ddb4d2
        )

    [_order_version] => Array
        (
            [0] => 2.6.4
        )

)

我可能使用了错误的动作挂钩?所有值都存在于数据库中.

Am I perhaps using the wrong action hook? All the values to exist in the database.

推荐答案

将操作更改为

add_action( 'woocommerce_checkout_update_order_meta', 'add_user_to_mailchimp', 1, 1 );

此操作在创建帖子元后触发,而'woocommerce_new_order'则不是这种情况.

This action fires after the post meta is created, which wasn't the case with 'woocommerce_new_order'.

这篇关于woocommerce_new_order操作未返回所有订单详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆