Woocommerce checkout form edit

Hi I am trying to add a custom form to woocommerce checkout. I got the form added fine. But now I need to send the field data to the woocommerce order backend with a hook.

I am using echo and get_post_meta

add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );

function my_custom_checkout_field_display_admin_order_meta($order){
echo ‘

’.__(‘pickuptime’).’: ’ . get_post_meta( $order->id, ‘pickuptime’, true ) . ‘

’;
}

But woocommerce is giving me an error

id was called incorrectly . Order properties should not be accessed directly. Backtrace: require(‘wp-admin/edit-form-advanced.php’), do_meta_boxes, WC_Meta_Box_Order_Data::output, do_action(‘woocommerce_admin_order_data_after_billing_address’), WP_Hook->do_action, WP_Hook->apply_filters, my_custom_checkout_field_display_admin_order_meta, WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong Please see Debugging in WordPress for more information. (This message was added in version 3.0.) in /home/thepieho/public_html/wp-includes/functions.php on line 5225 Not sure how to edit my code

Ok I got the error to go away by using this code
/// Display fields in the backend Order details screen.
add_action( ‘woocommerce_admin_order_data_after_billing_address’, ‘customfields_billing_checkbox_checkout_display’ );
function customfields_billing_checkbox_checkout_display( $order ){
echo '

Pickup Time and Day ’ . get_post_meta( $order->get_id(), ‘pickuptime’, true ) . ‘

’;
}

But all that shows is the label and not the input.

Sponsor our Newsletter | Privacy Policy | Terms of Service