在woocommerce的管理订单列表顶部添加一个按钮
我一直在努力寻找一个钩子,让我可以在 woocommerce 管理订单页面"的顶部添加一个按钮,但到目前为止没有成功.我找到了将操作按钮添加到操作列以及每个订单页面内的挂钩……但不是我现在需要的位置.
如果没有钩子,那么另一种方法.
更具体地说,我附上了一张我所指的地方的图片
有什么建议吗?
解决方案因为这与 Wordpress 相关,而不是特定于 Woocommerce,因为订单只是一种自定义帖子类型.因此以下代码将在现有字段和按钮之后的顶部区域显示一个自定义按钮:
add_action( 'manage_posts_extra_tablenav', 'admin_order_list_top_bar_button', 20, 1 );功能 admin_order_list_top_bar_button( $which ) {全球 $typenow;if ( 'shop_order' === $typenow && 'top' === $which ) {?><div class="alignleft 动作自定义"><button type="submit" name="custom_" style="height:32px;"class="button" value=""><?php回声 __( '自定义', 'woocommerce');?></按钮><?php}}
代码位于活动子主题(或主题)的 function.php 文件中.经过测试并有效.
<小时>继续:在woocommerce管理订单页面中的自定义按钮点击上运行一个功能
I have been struggling to find a hook that allows me to add a button to the top of the woocommerce admin "orders page", but so far unsuccessfully. I have found hooks to add action buttons to the action column, as well as inside each orders page ... but not where I need now.
If there is no hook, then an alternative approach.
More specifically, I attach an image with the place I am referring to
Any suggestions?
解决方案Because this is related to Wordpress and not specific to Woocommerce as Orders are just a custom post type. so the following code will display a custom button on the top zone just after existing fields and buttons:
add_action( 'manage_posts_extra_tablenav', 'admin_order_list_top_bar_button', 20, 1 );
function admin_order_list_top_bar_button( $which ) {
global $typenow;
if ( 'shop_order' === $typenow && 'top' === $which ) {
?>
<div class="alignleft actions custom">
<button type="submit" name="custom_" style="height:32px;" class="button" value=""><?php
echo __( 'Custom', 'woocommerce' ); ?></button>
</div>
<?php
}
}
Code goes in function.php file of your active child theme (or theme). Tested and works.
Continuation: Run a function on custom button click in woocommerce admin order page
相关文章