I need to insert into my custom table called license_table
**username**, **order id**, **Quantity**
This needs to be populated when an order is placed.
Username = customer's email id
Quantity = quantity (of the product)
order id=Order ID
i have used but not working
add_action( 'woocommerce_order_status_completed', 'my_function' );
function my_function($order_id) {
global $wpdb;
$order = new WC_order($order_id);
$customer_id= $order->id;
$email= $order->billing_email;
$email1= $order->id;
$table_name = "aitoe_license_table";
$wpdb->insert( $table_name, array(
'username' => $customer_id,
'order_id' => $email,
'number_of_cameras' => 12,
'boolean' => 'False',
) );
}
In your code there is strange things as
'order_id' => $email
that should be the Order ID value and not the email… Also$customer_id= $order->id;
that is NOT the ID of the customer user, but the Order ID, and$email1= $order->id;
that is not used and it's wrong… */Also what is strange is that you can have many items (products) in an order and your table can't handle this, as you should need also a line by item…