'Woocommerce Get Value of Custom Field in Checkout

i have a custom field in woocomerce checkout page created by this plugin Checkout Field Editor (Checkout Manager) for WooCommerce

enter image description here

now im trying to send request after client place an order with order data and that custom field

add_action( 'woocommerce_thankyou', function( $order_id ){
    $order = new WC_Order( $order_id );
    $data  = $order->get_data(); // The Order data

    if ( $order->status != 'failed' ) { 
            $url = "https://webhook.site/cb7a8476-72e5-422a-99fb-ca41fb39726d";
            $response = wp_remote_post(
                $url,
                array(
                    'body' => array(
                        'clientref' => $order->get_id(),
                        'name' =>  $order->get_shipping_first_name() ,
                        'area' =>  $data['billing']['area'], // custom field 
                        'uname' =>  "uname",
                        'upass' =>  "upass",
           
                    )
                )
            );
    }
});

The request was sent successfully but without this custom field i think the problem with accessing this custom filed data in this line

'area' =>  $data['billing']['area']

I tried to access that filed in more than one way and it didnt work

any ideas to solve this problem



Solution 1:[1]

Found this question on WordPress support here the answer is

get_post_meta($order_id, 'field_name', true)

i replaced that line with that line

'area' =>  $data['billing']['area']

and the prroblem is solved

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mohamed Elsobky