WC 3.3+的新更新:
Custom action button in admin orders list on Woocommerce 3.3+
以下是在管理订单列表中添加操作按钮的方法,其中包含与跟踪相关的自定义链接
(在中打开链接
新建窗口
根据要求)
:
// Add your custom order action button
add_action( 'woocommerce_admin_order_actions_end', 'add_custom_order_actions_button', 100, 1 );
function add_custom_order_actions_button( $order ) {
// Get the tracking number
$traking_number = get_post_meta( $order->get_id(), '_aftership_tracking_number', true );
if( empty($traking_number) ) return;
// Prepare the button data
$url = esc_url('https://track.aftership.com/'.$traking_number.'?');
$name = esc_attr( __('Tracking', 'woocommerce' ) );
$action = esc_attr( 'view tracking' ); // keep "view" class for a clean button CSS
// Set the action button
printf( '<a class="button tips %s" href="%s" data-tip="%s" target="_blank">%s</a>', $action, $url, $name, $name );
}
// The icon of your action button (CSS)
add_action( 'admin_head', 'add_custom_order_actions_button_css' );
function add_custom_order_actions_button_css() {
echo '<style>.view.tracking::after { font-family: woocommerce; content: "\e005" !important; }</style>';
}
代码进入功能。活动子主题(或主题)的php文件或任何插件文件。
已测试并正常工作。您将得到如下结果:
现在,要使您的跟踪号码可单击,您将在代码中替换此功能:
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><a href="https://track.aftership.com/'.$astracking.'?" target="_blank">'.$astracking . '</a></span>'; // display the data
break;
}
}