WooCommerce Filter

Description

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.

WooCommerce Shop Filter by http://pickplugins.com

Plugin Features

  • 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?

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
        ?>
        <div class="field-wrapper">
            <div class="label-wrapper">
                <label class=""><?php echo __('Custom Input','wc-shop-filter'); ?></label>
            </div>
            <div class="input-wrapper">
                <input type="search" placeholder="<?php echo __('Custom input','wc-shop-filter'); ?>" name="_custom_input" value="<?php echo $_custom_input; ?>">
            </div>
        </div>
    <?php
    endif;

}

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

Screenshots

  • screenshot-1
  • screenshot-2

Installation

  1. Install as regular WordPress plugin.
  2. Go your plugin setting via WordPress Dashboard and find “WooCommerce Shop Filter” activate it.

Contributors & Developers

“WooCommerce Filter” is open source software. The following people have contributed to this plugin.

Contributors

Translate “WooCommerce Filter” into your language.

Interested in development?

Browse the code, check out the SVN repository, or subscribe to the development log by RSS.

Changelog

1.0.1

* 12-10-2018 - add - added color attribute field
* 12-10-2018 - add - added size attribute field
* 12-10-2018 - fix - price range issue fixed.
* 12-10-2018 - fix - Order by issue fixed.

1.0.0

* 10/10/2018 Initial release.