【发布时间】:2018-08-04 04:05:48
【问题描述】:
由于 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>';
}
代码来自这个答案:Add custom URL link to admin order list page in WooCommerce
为了阻止它在新版本中工作,他们做了哪些更改?
我怎样才能让它在 Woocommerce 3.3+ 版中工作?
【问题讨论】:
-
有什么问题?该按钮不显示,或者当您单击它时没有任何反应?
-
我看了看你还没有定义变量$actions。它是什么意思?
-
按钮不再显示。他们把按钮从右边移到了中间,但由于某种原因,它坏了。
-
@AndrewSchultz 不是重复的,因为自 WC 3.3 版以来,管理员订单列表已通过一些增强功能进行了更改……操作按钮现在有所不同,并且涉及 Woocommerce 中的全新功能源代码。所以这个问题问题与这些变化直接相关......
标签: php wordpress button woocommerce orders