I am creating a table in my database with data for each order made in woocommerce.
here’s de code:
// 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')
);
}
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:
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!