2016-09-15 7 views
2

に配置された後、私は私のカスタムテーブルに挿入する必要がありますが、私は使用だけに挿入値の順序がWoocommerce

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', 
    )); 

    } 

答えて

2

を働いていない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 

と呼ばれます実際にあなたのコードをテストするのに役立ちます。あなたの質問を更新するテーブル(またはSQLクエリ)を作成するために使用しているコードを提供する必要があります。あなたのコードで

注文ID値ではなく、電子メールでなければなりません'order_id' => $emailとして奇妙なことがあります...また$customer_id= $order->id;顧客ユーザーのIDが、注文ID、およびされていないことあなたも必要とすべきであるとして$email1= $order->id;使用し、それは間違っていません... */

<?php 

#-------------------- code begins below -------------------------# 

add_action('woocommerce_order_status_completed', 'my_function'); 
function my_function($order_id) { 
    global $wpdb; 

    // Getting the order (object type) 
    $order = wc_get_order($order_id); 

    // Getting order items 
    $items = $order->get_items(); 
    $total_items_qty = 0; 

    // Iterating through each item (here we do it on first only) 
    foreach ($items as $item) { 
     $total_items_qty += $item["qty"]; 
    } 

    // Here are the correct way to get some values: 
    $customer_id   = $order->customer_user; 
    $billing_email   = $order->billing_email; 
    $complete_billing_name = $order->billing_first_name . ' ' . $order->billing_last_name; 

    // Getting the user data (if needed) 
    $user_data    = get_userdata($customer_id); 
    $customer_login_name = $user_data->user_login; 
    $customer_login_email = $user_data->user_email; 

    // "$wpdb->prefix" will prepend your table prefix 
    $table_name = $wpdb->prefix."license_table"; 

    // This array is not correct (as explained above) 
    $data = array( 
     'username'   => $customer_login_name, 
     'order_id'   => $order_id, 
     'number_of_cameras' => $total_items_qty, 
     'boolean'   => 'false', 
    ); 

    $wpdb->insert($table_name, $data); 

} 

#-------------------- code end -------------------------# 

?> 

も奇妙である何、あなたが順番に多くの項目(製品)を持つことができ、あなたのテーブルには、これを扱うことができないということですアルアイテムごとに...

関連する問題