dongxiaoxiao1983 2015-10-23 23:16
浏览 17
已采纳

too long

I need to get the following information after checkout:

  • order ID
  • order date
  • customer name (F/L)
  • customer phone
  • customer email

Which will be put into the session array and then stored in a seperate database. Currently in my theme's functions.php file I have the following:

    //get completed order data:
    add_action( 'woocommerce_order_status_completed', 'my_function' );
    function my_function($order_id) {
    $order = new WC_Order( $order_id );
    $_SESSION['kiosk_data']['order_number'] = $order->[what would I use here?];
    $_SESSION['kiosk_data']['order_date'] = $order->[what would I use here?];
    $_SESSION['kiosk_data']['f_name'] = $order->[what would I use here?];
    $_SESSION['kiosk_data']['l_name'] = $order->[what would I use here?];
    $_SESSION['kiosk_data']['phone'] = $order->[what would I use here?];
    $_SESSION['kiosk_data']['email'] = $order->[what would I use here?];

    //for testing:
    $kioskDataFile = './testFile.txt';
    $kioskData = "kioskID: ".$_SESSION['kiosk_data']['kioskID']."
";
    $kioskData.= "order date: ";
    $kioskData.= $order->order_date;
    $kioskData.= "
";
    $kioskData.= "order ID: ";
    $kioskData.= $order->id;
    $kioskData.= "
";
    $kioskData.= "order key: ";
    $kioskData.= $order->order_key;
    $kioskData.= "
";
    $kioskData.= "first name: ";
    $kioskData.= $order->billing_first_name;
    $kioskData.= "
";
    $kioskData.= "last name: ";
    $kioskData.= $order->billing_last_name;
    $kioskData.= "
";
    $kioskData.= "phone: ";
    $kioskData.= $order->billing_phone;
    $kioskData.= "
";
    $kioskData.= "email: ";
    $kioskData.= $order->billing_email;
    $kioskData.= "


";

    file_put_contents($kioskDataFile, $kioskData, FILE_APPEND);
    }

Being very new to WP/woocommerce I'm really not sure how to go about capturing this data (tried several google searches to no avail).

  • 写回答

2条回答 默认 最新

  • doulin1867 2015-11-06 17:46
    关注

    Got it working by changing the code as follows and removing the 'add_action' component and function, and moved it to the "thankyou.php" page under child theme/woocommerce/checkout.

        $kioskDataFile = './logs/kiosk_log';
    
        $kioskData['description'] = "kiosk site - thankyou.php";
        $kioskData['kiosk_id'] = $_SESSION['kiosk_data']['kioskID'];
        $kioskData['order_date'] = $order->order_date;
        $kioskData['month'] = date("m");
        $kioskData['year'] = date("Y");
        $kioskData['order_number'] = $order->get_order_number();
        $kioskData['order_id'] = $order->id;
        $kioskData['order_key'] = $order->order_key;
        $kioskData['first_name'] = $order->billing_first_name;
        $kioskData['last_name'] = $order->billing_last_name;
        $kioskData['phone'] = $order->billing_phone;
        $kioskData['email'] = $order->billing_email;
    
        $s_kioskData = serialize($kioskData);
        $s_kioskData.= "
    ";
        file_put_contents($kioskDataFile, $s_kioskData, FILE_APPEND);
    

    I've serialized the array data so I can load it into an array via file() from the log file and sort/parse it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题