我正在尝试使用$ wpdb-> insert在WordPress中的MySQL数据库中进行插入。这只是一个简单的日志,但不起作用。
我正在尝试从WooCommerce购买后收到的订单中保存一些基本物品。我添加了代码的页面是order-details.php,属于WooCommerce。
代码:
<?php
do_action( 'woocommerce_order_details_before_order_table_items', $order );
$fecha = date('Y-m-d H:i:s');
$creditos =0;
foreach ( $order_items as $item_id => $item ) {
$item_quantity = $item->get_quantity();
$product = $item->get_product();
$product_name = $product->get_name();
if( $product_name == "orián (paquete mínimo)"){
$creditos=15;
}
if( $product_name == "Andrómeda (paquete medio)"){
$creditos=30;
}
if( $product_name == "Lira (paquete básico)"){
$creditos=50;
}
if( $product_name == "Cisne (paquete real + 15 créditos)"){
$creditos=65;
}
if( $product_name == "Perseo (Paquete Premium + 30 créditos)"){
$creditos=120;
}
echo $item_quantity." ".$product_name." ".$creditos." ".$fecha." ".get_current_user_id();
$wpdb->insert(
'registrorden',
array(
'idusuario' => get_current_user_id(),
'paquete' => $product_name,
'cantidad' => $item_quantity,
'creditos' => $creditos
),
array(
'%d',
'%s',
'%d',
'%d'
)
);
wc_get_template( 'order/order-details-item.php', array(
'order' => $order,
'item_id' => $item_id,
'item' => $item,
'show_purchase_note' => $show_purchase_note,
'purchase_note' => $product ? $product->get_purchase_note() : '',
'product' => $product,
) );
}
do_action( 'woocommerce_order_details_after_order_table_items', $order );
?>
我添加的代码:
$wpdb->insert(
'registrorden',
array(
'idusuario' => get_current_user_id(),
'paquete' => $product_name,
'cantidad' => $item_quantity,
'creditos' => $creditos
),
array(
'%d',
'%s',
'%d',
'%d'
)
);
Here is a snapshot of the table和here is the error。
该如何解决?