![](/img/trans.png)
[英]How to add filter to hide out of stock products when searching for Upsells and Cross-sells in admin panel on the Linked Products tab (in woocommerce)?
[英]Trying to add search bar admin panel menu bar searching woocommerce products
尝试将产品搜索栏添加到将执行Woocommerce产品搜索的Wordpress管理栏后端。 它位于后端管理菜单栏中的顶部,因此无论您在后端在哪里,都可以搜索woo的产品。 我很近,但是在小的绊脚石上有错。 尝试使用搜索时,默认情况下是发布搜索而不是产品。
//Add Search To Admin Bar
function boatparts_admin_bar_form() {
global $wp_admin_bar;
$wp_admin_bar->add_menu(array(
'id' => 'boatparts_admin_bar_form',
'parent' => 'top-secondary',
'title' => '<form method="get" action="'.get_site_url().'/wp-admin/edit.php?post_type=product">
<input name="s" type="text" style="height:20px;margin:5px 0;line-height:1em;"/>
<input type="submit" style="height:18px;vertical-align:top;margin:5px 0;padding:0 2px;" value="Search Products"/>
</form>'
));
}
add_action('admin_bar_menu', 'boatparts_admin_bar_form');
在我的孩子主题的function.php中有它。 让我发疯试图解决它。
您应该使用post-type参数添加隐藏字段 :
<input name="post_type" value="product" type="hidden">
此外,我添加了一些代码,用于在表单提交后在表单中显示搜索查询,并对按钮样式进行了小幅修复。
固定的代码段如下:
//Add Search To Admin Bar
function boatparts_admin_bar_form() {
global $wp_admin_bar;
$search_query = '';
if ( $_GET['post_type'] == 'product' ) {
$search_query = $_GET['s'];
}
$wp_admin_bar->add_menu(array(
'id' => 'boatparts_admin_bar_form',
'parent' => 'top-secondary',
'title' => '<form method="get" action="'.get_site_url().'/wp-admin/edit.php?post_type=product">
<input name="s" type="text" value="' . $search_query . '" style="height:20px;margin:5px 0;line-height:1em;"/>
<input type="submit" style="padding:3px 7px;line-height:1" value="Search Products"/>
<input name="post_type" value="product" type="hidden">
</form>'
));
}
add_action('admin_bar_menu', 'boatparts_admin_bar_form');
搜索结果样本:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.