Jump to content

Trying to add search bar admin panel menu bar searching woocommerce products


ljambrose
Go to solution Solved by ljambrose,

Recommended Posts

Trying to add a product search bar to Wordpress admin bar backend that will do Woocommerce product search. It will be located in the backend Admin Menu bar a top so that no matter where you are in back end it will allow to search woo's products. I am close but faulting at small stumbling block. When trying to use the search it is defaulting to post search instead of products.

 

 

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

 

 

Have it in my child theme's function.php. Driving me nuts trying to figure it out.

Link to comment
Share on other sites

  • Solution

Lucky_hunter figured it out for me on another Forum. Adding code here for anyone who is looking for something like this.

 

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

 

Enjoy!

Consider this topic closed

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.