Php 将订单放入自定义表后,将值插入自定义表
我需要在名为许可证\u表的自定义表中插入Php 将订单放入自定义表后,将值插入自定义表,php,mysql,wordpress,woocommerce,hook-woocommerce,Php,Mysql,Wordpress,Woocommerce,Hook Woocommerce,我需要在名为许可证\u表的自定义表中插入 **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 我用过但不工作 add_action( 'woocommerce_order_statu
**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
我用过但不工作
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',
) );
}
为了真正帮助您(并测试代码),您应该提供用于创建表(或sql查询)更新问题的代码
在你的代码中有一些奇怪的东西,比如,'order\u id'=>$email
应该是order id值而不是email…还有$customer\u id=$order->id代码>
不是客户用户的ID,而是订单ID,以及$email1=$Order->ID代码>
未使用且错误的代码*/
另外奇怪的是,一个订单中可以有许多项目(产品),而您的表无法处理这一点,因为您还需要一行一行的项目