enter data from the thank you page to a custom table | wocommerce

Viewed 23

I want to enter some data to the fields of the custom table, but they do not insert

What I want to do is extract the data from the order and save it in a custom table

function hwn_add_thankyou_custom_text_with_order_details($order_id) {

$order = wc_get_order( $order_id );

$billing_first_name = $order->get_billing_first_name();
$billing_city = $order->get_billing_city();
$billing_phone = $order->get_billing_phone();
$orde_id = $order->get_id();


 global $wpdb;
 
  $table = "{wpdb->prefix}checkout";

    $data = [ 
        'CheckoutId' => null,
        'order_id' => $orde_id,
        'Nombre' => $billing_first_name,
        'Ciudad' => $billing_city,
        'Numero' => $billing_phone,
        'NumeroC' => $billing_phone
    ];

    $wpdb->insert($table,$data);
    
 
}

add_action( 'woocommerce_thankyou', 'hwn_add_thankyou_custom_text_with_order_details' );
0 Answers
Related