Woocommerce Feature request

Support forumCategory: Feature requestsWoocommerce Feature request
MedicAppointments asked 6 years ago
Mr Loncar,   Is it possible to have appointement data in the woocommerce orders ? I mean, to have a column with the appointment date and time. It would be also interesting to add a customer button to delete the appointment from the oders tab. Indeed for instance with a 48h limit before the appointement the customer could cancel his appointement. Thank you in advance for this plugin and your time.
2 Answers
MedicAppointments answered 6 years ago
After some researches, I have found how to display datas on woocommerce thanks to this StackOverflow page https://stackoverflow.com/a/48445607/5959452 Here the code to edit and insert into a plugin or a child theme :
Start your code here
// Store custom field label and value in cart item data
add_action( 'woocommerce_add_cart_item_data', 'save_my_custom_checkout_field', 10, 2 );
function save_my_custom_checkout_field( $cart_item_data, $product_id ) {
    if( isset( $_REQUEST['custom_slug'] ) ) {
        $cart_item_data['custom_data']['label'] = get_post_meta($product_id, 'InputText1', true);
        $cart_item_data['custom_data']['value'] = sanitize_text_field( $_REQUEST['custom_slug'] );
        $cart_item_data['custom_data']['ukey'] = md5( microtime().rand() );
    return $cart_item_data;

// Display items custom fields label and value in cart and checkout pages
add_filter( 'woocommerce_get_item_data', 'render_meta_on_cart_and_checkout', 10, 2 );
function render_meta_on_cart_and_checkout( $cart_data, $cart_item ){

    $custom_items = array();
    /* Woo 2.4.2 updates */
    if( !empty( $cart_data ) ) {
        $custom_items = $cart_data;
    if( isset( $cart_item['custom_data'] ) ) {
        $custom_items[] = array(
            'name' => $cart_item['custom_data']['label'],
            'value' => $cart_item['custom_data']['value'],
    return $custom_items;

// Save item custom fields label and value as order item meta data
add_action('woocommerce_add_order_item_meta','save_in_order_item_meta', 10, 3 );
function save_in_order_item_meta( $item_id, $values, $cart_item_key ) {
    if( isset( $values['custom_data'] ) ) {
        wc_add_order_item_meta( $item_id, $values['custom_data']['label'], $values['custom_data']['value'] );
But I still don't know how to get the date and hour from the easy appointment form.
Nikola Loncar Staff answered 6 years ago
Hi it will require some custom code for that one but it can be done for sure. Best regards, Nikola