en
  English
Phone:  +1 (217) 636-4164
Skype:  onegbits
  1. Home
  2. Blog
  3. Introducing plugin WooCommerce Shop Filter

Introducing plugin WooCommerce Shop Filter

11

Oct, 18

817

In this article, With the Introducing another one of other WordPress plugins are at your service.

Introducing plugin WooCommerce Shop Filter

Default WooCommerce shop page isn’t good enough for search and filter product as user needs, this plugin allows user to filter and search by their own needs and find the best product they are looking for.

Features plugin WooCommerce Shop Filter

  • Filter by keywords
  • Filter by product categories
  • Filter by product tags
  • Filter by price range
  • Filter by order & order by
  • Filter onsale product
  • Filter in-stock
  • Filter by SKU

How to use plugin WooCommerce Shop Filter?

Please go to “Widgets” page and see there is a widget “Woo Shop Filter”, you can use this on sidebars.
There is no option currently, we will update soon.

 

How to add custom search field and filter products?

you can add custom search field by action hook and filter products as well,

Step 1:

Add search input field

add_action('WooShopFilter_fields','WooShopFilter_field_my_custom_input', 30);
function WooShopFilter_field_my_custom_input(){

    $WooShopFilter = isset($_GET['WooShopFilter']) ? sanitize_text_field($_GET['WooShopFilter']) :""; // check this to ensure for is submitted from WooShopFilter.
    $_custom_input = isset($_GET['_custom_input']) ? sanitize_text_field($_GET['_custom_input']) :""; // Do not forget to sanitization

    if(!$WooShopFilter):
        $_custom_input = '';
    endif;


    /*
     *
     * you can check conditional here.
     *
     * if(is_shop()):
     * execute code only shop page
     * endif;
     *
     * */

    if(is_shop()):
        // this will only display under shop page and hide others page
        ?>
 

    

Step 2

verify input variable and put on product query arguments

add_action( 'woocommerce_product_query', 'WooShopFilter_pre_get_posts_query_my_custom_input', 99 );
function WooShopFilter_pre_get_posts_query_my_custom_input( $query_args ){

    $WooShopFilter = isset($_GET['WooShopFilter']) ? sanitize_text_field($_GET['WooShopFilter']) : "";
    $_custom_input = isset($_GET['_custom_input']) ? sanitize_text_field($_GET['_custom_input']) :""; // Do not forget to sanitization

    if($WooShopFilter && $_custom_input){

        // you can get ans set query arguments
        // try var_dump($query_args) to see available query arguments, like tax_query, meta_query, order, orderby

        $s = $query_args->get( 's' );
        $query_args->set( 's', $_custom_input );
    }

}



How to remove existing input fields?

By action hook you can simply remove any input fields exist.

remove_action('WooShopFilter_fields','WooShopFilter_field_keyword',30);
remove_action('WooShopFilter_fields','WooShopFilter_field_categories',30);
remove_action('WooShopFilter_fields','WooShopFilter_field_tags',30);
remove_action('WooShopFilter_fields','WooShopFilter_field_price_range',30);
remove_action('WooShopFilter_fields','WooShopFilter_field_order',30);
remove_action('WooShopFilter_fields','WooShopFilter_field_orderby',30);
remove_action('WooShopFilter_fields','WooShopFilter_field_onsale',30);
remove_action('WooShopFilter_fields','WooShopFilter_field_in_stock',30);
remove_action('WooShopFilter_fields','WooShopFilter_field_keyword',30);
remove_action('WooShopFilter_fields','WooShopFilter_field_sku',30);

 

 

How to install wordpress plugin WooCommerce Shop Filter:

  1. Upload the wordpress plugin WooCommerce Shop Filter files to the /wp-content/plugins/woo-shop-filter, or install the plugin through the WordPress plugins screen directly.
  2. Activate the plugin through the ‘Plugins’ screen in WordPress

Download link

If you have a question about this article, You can let us know via comments and we will get back to you.

Leave A Comment