后端订单列出了Woocommerce 3.3+中的自定义操作按钮 [英] Backend orders list custom action buttons in Woocommerce 3.3+

查看:111
本文介绍了后端订单列出了Woocommerce 3.3+中的自定义操作按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于WooCommerce版本3.3+,下面的代码(在管理订单列表中显示自定义操作按钮)不再起作用。

  //添加自定义订单操作按钮
add_action('woocommerce_admin_order_actions_end','add_custom_order_actions_button',100,1) ;
function add_custom_order_actions_button($ order){

//获取跟踪号
$ traking_number = get_post_meta($ order-> get_id(),‘_aftership_tracking_number’,true);
if(empty($ traking_number))return;

//准备按钮数据
$ url = esc_url(’https://track.aftership.com/’.$traking_number。’?’);
$ name = esc_attr(__('Tracking','woocommerce'));
$ action = esc_attr('查看跟踪'); //保持视图类的清洁按钮CSS

//设置操作按钮
printf('< a class = button tips%s href =%s data-tip =%s target = _ blank>%s< / a>',$ action,$ url,$ name,$ name);
}

//操作按钮(CSS)的图标
add_action('admin_head','add_custom_order_actions_button_css');
函数add_custom_order_actions_button_css(){
echo’< style> .view.tracking :: after {font-family:woocommerce;内容: \e005!重要; }< / style>’;
}

代码来自此答案:


这里我不使用 woocommerce_admin_order_actions 常规动作挂钩,但我使用了一个不寻常的挂钩,允许在单独的浏览器窗口中显示跟踪页面(或标签)



Since WooCommerce version 3.3+ the code below that displays a custom action button in admin order list, doesn't work anymore.

// 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>';
}

Code come from this answer: Add custom URL link to admin order list page in WooCommerce

What did they change to prevent it from working in the new version?
How can I make it work in Woocommerce version 3.3+?

解决方案

Here is the correct way to get this working, as this was the code from one of my answers, that will load in a separate browser window (or tab) the corresponding tracking page.

hook woocommerce_admin_order_actions_end still exist and works. What has changed in vesion 3.3+ is the function that displays the buttons wc_render_action_buttons() and so the displayed buttons html structure and classes too.
Why? … Because that order list display has been enhanced in version 3.3+.

The code:

// 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' ) );
    $class  = esc_attr( 'tracking' );

    // Custom action button (with a target='_blank' opening a new browser window)
    printf( '<a class="button wc-action-button wc-action-button-%s %s" href="%s" title="%s" target="_blank">%s</a>', $class, $class, $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>.wc-action-button-tracking::after { font-family: woocommerce !important; content: "\e01a" !important; }</style>';
}

Code goes in function.php file of your active child theme (or theme).

Tested and works only for woocommerce version 3.3+

Here I don't use woocommerce_admin_order_actions usual action hook, but instead I use an unusual hook, to allow displaying the tracking page in a separate browser window (or tab)

这篇关于后端订单列出了Woocommerce 3.3+中的自定义操作按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆