如何获取woocommerce_payment_complete操作中的结帐字段?

时间:2016-06-03 07:19:39

标签: php wordpress wordpress-plugin woocommerce checkout

我想在订单完成时触发另外发送带有结帐字段的自定义电子邮件。如何访问woocommerce_payment_complete内的结帐字段?

或者我应该使用其他一些动作吗?

add_action( 'woocommerce_payment_complete','new_email_notification' );
function new_email_notification($order_id) {

    global $woocommerce;
    $checkout = $woocommerce->checkout();
    $order = new WC_Order( $order_id );
    $myuser_id = (int)$order->user_id;
    $user_info = get_userdata($myuser_id);
    $items = $order->get_items();
    foreach ($items as $item) {
    ...

我能够获取订单信息,但不能获取结帐字段。

1 个答案:

答案 0 :(得分:0)

我知道这个问题是很久以前问过的,可能已经由OP解决了-但它仍然是在Google上弹出的窗口-所以我会回答:)

add_action( 'woocommerce_payment_complete','new_email_notification' );
function new_email_notification($order_id) 
{
    //$_POST will contain all fields in the form, and is easily accessed by their  form names 
    $aFields = $_POST;
    $sFieldNameYouWant = $aFields['field_name_you_want];
}