Add a custom meta box on order edit pages and display it on the customer order pages

Viewed 4326

In WooCommerce, would like to add a custom meta box on WooCommerce Admin order pages.

In this box, I just want to enter a tracking number in a text field that saves to that order.

Then on the customer view order page, I would like to display a button that opens a modal with tracking information. The modal will just pull in an iframe with a URL that has the tracking number at the end.

The courier company I'm using has a tracking website so for now I'm just going to display the iframe in the modal using the tracking number that was entered on the admin order page.

Please let me know if this doesn't make sense.

How do I save and use it?

I have this so far:

// Add meta box
function tcg_tracking_box() {
    add_meta_box(
        'tcg-tracking-modal',
        'The Courier Guy Tracking',
        'tcg_meta_box_callback',
        'shop_order',
        'side',
        'high'
    );
}
add_action( 'add_meta_boxes', 'tcg_tracking_box' );

// Callback
function tcg_meta_box_callback( $post )
{
    $values = get_post_custom( $post->ID );
    $text = isset( $values['tcg_tracking_box'] ) ? esc_attr( $values['tcg_tracking_box'][0] ) : '';
    echo '<input type="text" name="tcg_tracking_box" id="tcg_tracking_box" value="' . $text . '" />';
}

// Saving
add_action( 'save_post', 'tcg_tracking_box_save' );
function tcg_tracking_box_save( $post_id )
{

}
1 Answers
Related