Themify WooCommerce Product Filter Shortcode

Below, you’ll find a detailed guide on how to add the Themify – WooCommerce Product Filter Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Themify – WooCommerce Product Filter Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Themify – WooCommerce Product Filter Plugin and the shortcodes it provides:

Plugin Icon
Themify – WooCommerce Product Filter

"Themify – WooCommerce Product Filter is a powerful plugin designed to enhance your ecommerce website. It simplifies product searches by providing advanced filtering options. Boost sales with seamless navigation."

★★★✩✩ (68) Active Installs: 30000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [searchandfilter]

Themify WooCommerce Product Filter [searchandfilter] Shortcode

The Themify-WC-Product-Filter shortcode is designed to create a customizable product filter for WooCommerce. This shortcode checks if an ID is provided in the shortcode attributes. If not, it returns nothing. If an ID is provided, it sanitizes the ID and retrieves the related form from the options. If the form doesn’t exist, it returns nothing. If the script isn’t enqueued, it enqueues it and loads WooCommerce scripts. It then checks if there is a ‘wpf’ request. If so, it parses the query and assigns the request to the shortcode ID. Finally, it creates a new form and returns the public template of the form with the result page and request.

Shortcode: [searchandfilter]

Parameters

Here is a list of all possible searchandfilter shortcode parameters and attributes:

  • id – Unique identifier for the specific filter form.
  • wpf – Parameter used to override the ‘id’ from the request.

Examples and Usage

Basic example – The following shortcode will call the ‘searchandfilter’ function by referencing the ID of the form you wish to display.

[searchandfilter id="1" /]

Advanced examples

1. The next example includes an additional parameter ‘wpf’ in the request. This parameter is used to specify the form that the user wants to load. If the form with the requested ‘id’ is not found, the plugin will try to load the form with the ‘wpf’ parameter.

[searchandfilter id="1" wpf="2" /]

2. In this example, the shortcode is used to display a form with a specific ‘id’, but if this form is not found, the plugin will try to load the form with the ‘wpf’ parameter. Additionally, the ‘parse_query’ parameter is used to parse the request and return the form that matches the specific query.

[searchandfilter id="1" wpf="2" parse_query="true" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [searchandfilter] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'searchandfilter', array( $this, 'shortcode' ) );

Shortcode PHP function:

function shortcode( $atts ) {
		if ( empty( $atts['id'] ) ) {
			return;
		}
		$id = sanitize_text_field( $atts['id'] );
		$option = WPF_Options::get_option( $this->plugin_name, $this->version );
		$forms = $option->get();
		if ( empty( $forms[ $id ] ) ) {
			return;
		}
		if ( !wp_script_is( $this->plugin_name ) ) {
			wp_enqueue_script( $this->plugin_name );
			self::load_wc_scripts();
		}
		$request = array();
		$this->shortcode_id = $id;
		if ( ! empty( $_REQUEST['wpf'] ) ) {
			$option = WPF_Options::get_option( $this->plugin_name, $this->version );
			$forms = $option->get();
			if ( !empty( $forms[ $_REQUEST['wpf'] ] ) ) {
				$this->shortcode_id = $_REQUEST['wpf'];
				$request = $this->parse_query( $_REQUEST, $forms[ $_REQUEST['wpf'] ], false );
			}
		}
		$wpf_form = new WPF_Form( $this->plugin_name, $this->version, $id );
		return $wpf_form->public_themplate( $forms[ $id ], self::$result_page, $request );
	}

Code file location:

themify-wc-product-filter/themify-wc-product-filter/public/class-wpf-public.php

Conclusion

Now that you’ve learned how to embed the Themify – WooCommerce Product Filter Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *