![](/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.