# Сreating a table in my database with data for each order made in WooCommerce

**URL:** <https://community.hivepress.io/t/reating-a-table-in-my-database-with-data-for-each-order-made-in-woocommerce/6464>\
**Category:** Marketplace\
**Tags:** marketplace, code\
**Created:** [July 4, 2023, 2:55pm UTC](https://community.hivepress.io/t/reating-a-table-in-my-database-with-data-for-each-order-made-in-woocommerce/6464 "2023-07-04T14:55:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tuuggo](https://community.hivepress.io/user_avatar/community.hivepress.io/tuuggo/32/5998_2.png) [@tuuggo](https://community.hivepress.io/u/tuuggo)\
**Post date:** [July 4, 2023, 2:55pm UTC](https://community.hivepress.io/t/reating-a-table-in-my-database-with-data-for-each-order-made-in-woocommerce/6464/1 "2023-07-04T14:55:54Z")

</div>

I am creating a table in my database with data for each order made in woocommerce.

here’s de code:

```auto
// Hook callback for new order event
function update_information_for_insurance_on_new_order($order_id) {
    // Retrieve necessary data from the order object, user information, and vendor information
    $order = wc_get_order($order_id);
    $user_id = $order->get_customer_id();

    // Retrieve user and vendor details
    $user = get_user_by('ID', $user_id);

    // Insert or update the data in your custom table
    global $wpdb;
    $table_name = $wpdb->prefix . 'information_for_insurance';

    $wpdb->replace(
        $table_name,
        array(
            'order_id' => $order_id,
            'user_id' => $user_id,
            'user_name' => $user->display_name,
            'user_email' => $user->user_email,
            'billing_first_name' => $order->get_billing_first_name(),
            'billing_last_name' => $order->get_billing_last_name(),
            'billing_phone' => $order->get_billing_phone(),
            'billing_nif' => $order->get_meta('_billing_nif'),
        ),
        array('%d', '%d', '%s', '%s', '%s', '%s', '%s', '%s')
    );
}

```

```auto
add_action('woocommerce_new_order', 'update_information_for_insurance_on_new_order');

// Hook callback for new booking event
function update_information_for_insurance_on_new_booking($booking_id) {
    // Retrieve necessary data from the booking object, user information, and vendor information
    $order = wc_get_order($booking_id);
    $user_id = $order->get_customer_id();

    // Retrieve user and vendor details
    $user = get_user_by('ID', $user_id);

    // Insert or update the data in your custom table
    global $wpdb;
    $table_name = $wpdb->prefix . 'information_for_insurance';

    $wpdb->replace(
        $table_name,
        array(
            'order_id' => $booking_id,
            'user_id' => $user_id,
            'user_name' => $user->display_name,
            'user_email' => $user->user_email,
            'billing_first_name' => $order->get_billing_first_name(),
            'billing_last_name' => $order->get_billing_last_name(),
            'billing_phone' => $order->get_billing_phone(),
            'billing_nif' => $order->get_meta('_billing_nif'),
        ),
        array('%d', '%d', '%s', '%s', '%s', '%s', '%s', '%s')
    );
}

```

`add_action('woocommerce_new_booking', 'update_information_for_insurance_on_new_booking');`

here’s what it does:

 ![image](https://community.hivepress.io/uploads/default/original/2X/b/b3f19b9d2343ef6f7e568a897f8a79d5fcb73a23.png)

I am trying to get the listing’s title, attributes, the name of the vendor, and also his attributes to show in that table. I’ve tried making queries but didn’t work or I just made them wrong. Can anyone help please?

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![andrii](https://community.hivepress.io/user_avatar/community.hivepress.io/andrii/32/2951_2.png) [@andrii](https://community.hivepress.io/u/andrii)\
**Post date:** [July 5, 2023, 12:35pm UTC](https://community.hivepress.io/t/reating-a-table-in-my-database-with-data-for-each-order-made-in-woocommerce/6464/5 "2023-07-05T12:35:30Z")

</div>

Hi,

Unfortunately, we can’t provide more details because this is a WooCommerce and WordPress customization. Also, note that the vendor id is stored in the `hp_vendor` meta field of the order, and the vendor itself is a post type of the `hp_vendor` type.

​I hope this is helpful to you.

---

<div class="post-metadata">

**Author:** ![system](https://community.hivepress.io/user_avatar/community.hivepress.io/system/32/13990_2.png) [@system](https://community.hivepress.io/u/system)\
**Post date:** [August 4, 2023, 12:35pm UTC](https://community.hivepress.io/t/reating-a-table-in-my-database-with-data-for-each-order-made-in-woocommerce/6464/6 "2023-08-04T12:35:55Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
