Hi I am trying to add an AfterShip tracking button or link to my Admin Order list in the backend. I have succesfully created a new column that displays the tracking number for each order. However, I would like to make the tracking number clickable. Or, as an alternative, create an action button that opens a new tab and tracks the number in the Tracking Number column.
The URL format I need is as follows: https://track.aftership.com/LS325245095CN?
Notice that there is a question mark appended to the tracking number. I would need to do this with the action, since the question mark symbol is not used when entering the tracking number.
Here is the code I am using for displaying the tracking number column in the admin orders list in the backend:
//Start Add Tracking Number to Admin Orders List
//Start Add Header to List
add_filter( 'manage_edit-shop_order_columns', 'custom_shop_order_column',
12, 1 );
function custom_shop_order_column($columns)
{
// Set "Actions" column after the new colum
$action_column = $columns['order_actions']; // Set the title in a variable
unset($columns['order_actions']); // remove "Actions" column
//add the new column "New Tracking Number"
$columns['order_astracking'] = '<span>'.__( 'Tracking Number','woocommerce').'</span>'; // title
// Set back "Actions" column
$columns['order_actions'] = $action_column;
return $columns;
}
//END Add Header to List
//START Add Tracking Number Data to List
add_action( 'manage_shop_order_posts_custom_column' ,
'custom_order_list_column_content', 10, 2 );
function custom_order_list_column_content( $column, $post_id )
{
// HERE get the data from your custom field (set the correct meta key below)
$astracking = get_post_meta( $post_id, '_aftership_tracking_number', true );
if( empty($astracking)) $astracking = '';
switch ( $column )
{
case 'order_astracking' :
echo '<span>'.$astracking.'</span>'; // display the data
break;
}
}
//END Add Tracking Number Data to List
//START Make Tracking Number Data Searchable in Admin Orders List
add_filter( 'woocommerce_shop_order_search_fields',
'astracking_search_fields', 10, 1 );
function astracking_search_fields( $meta_keys ){
$meta_keys[] = '_aftership_tracking_number';
return $meta_keys;
}
//END Make Tracking Number Data Searchable in Admin Orders List
//END Add Tracking Number to Admin Orders List
I got this code here on Stackoverflow.. awesome resource.
Add custom columns to admin orders list in WooCommerce backend
Any help or suggestions you could provide, would be greatly appreciated. Thanks in advance!