Hey. I am trying to add an AfterShip tracking button or a link to my list of administrators in the backend. I have successfully created a new column that displays the tracking number for each order. However, I would like to make the tracking number clickable. Or, alternatively, create an action button that opens a new tab and tracks the number in the Tracking Number column.
The URL format I need is this:
https://track.aftership.com/LS325245095CN ?
Please note that a question mark has been added to the tracking number. I will need to do this with an action, since the question mark symbol is not used when entering the tracking number.
Here is the code I use to display the tracking number column in the list of admin orders in the backend:
add_filter( 'manage_edit-shop_order_columns', 'custom_shop_order_column',
12, 1 );
function custom_shop_order_column($columns)
{
$action_column = $columns['order_actions'];
unset($columns['order_actions']);
$columns['order_astracking'] = '<span>'.__( 'Tracking Number','woocommerce').'</span>';
$columns['order_actions'] = $action_column;
return $columns;
}
add_action( 'manage_shop_order_posts_custom_column' ,
'custom_order_list_column_content', 10, 2 );
function custom_order_list_column_content( $column, $post_id )
{
$astracking = get_post_meta( $post_id, '_aftership_tracking_number', true );
if( empty($astracking)) $astracking = '';
switch ( $column )
{
case 'order_astracking' :
echo '<span>'.$astracking.'</span>';
break;
}
}
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;
}
I got this code here on Stackoverflow .. an amazing resource.
Add custom columns to list of admin orders in the WooCommerce backend
Any help or suggestions you could provide would be greatly appreciated. Thanks in advance!
source
share