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 制裁名单20240508芯片厂商
  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接