Home Forums WoodMart support forum Price Filter Widget – Clear All Button

Price Filter Widget – Clear All Button

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #137899

    newsprince
    Participant

    @XTEMOS Team

    Please enable also when someone is filtering via the price or price range widget to show them the Clear all button.

    Currently when you filter with price the clear all button is not enabled afterwards.

    Consider adding the following code to enable it.

    /wp-content/themes/woodmart/inc/integrations/woocommerce/template-tags.php

    /**
     * ------------------------------------------------------------------------------------------------
     * Clear all filters button
     * ------------------------------------------------------------------------------------------------
     */
    
    if( ! function_exists( 'woodmart_clear_filters_btn' ) ) {
    	function woodmart_clear_filters_btn() {
    		if ( ! woodmart_woocommerce_installed() ) {
    			return;
    		}
    
    		global $wp;  
    		$url = home_url( add_query_arg( array( $_GET ), $wp->request ) );
    		$_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes();
    		$min_price = isset($_GET['min_price']) ? wc_clean($_GET['min_price']) : 0;
                    $max_price = isset($_GET['max_price']) ? wc_clean($_GET['max_price']) : 0;
    		if ( 0 < count( $_chosen_attributes ) || 0 < $min_price || 0 < $max_price) {
    			$reset_url = strtok( $url, '?' );
    			if ( isset( $_GET['post_type'] ) ) $reset_url = add_query_arg( 'post_type', wc_clean( wp_unslash( $_GET['post_type'] ) ), $reset_url );
    			?>
    				<div class="woodmart-clear-filters-wrapp">
    					<a class="woodmart-clear-filters" href="<?php echo esc_url( $reset_url ); ?>"><?php echo esc_html__( 'Clear filters', 'woodmart' ); ?></a>
    				</div>
    			<?php
    		}
    	}
    	add_action( 'woodmart_before_active_filters_widgets', 'woodmart_clear_filters_btn' );
    }

    To make it work i just added

    $min_price = isset($_GET['min_price']) ? wc_clean($_GET['min_price']) : 0;
    $max_price = isset($_GET['max_price']) ? wc_clean($_GET['max_price']) : 0;

    and

    if ( 0 < count( $_chosen_attributes ) || 0 < $min_price || 0 < $max_price) {

    Thank you.

    #137907

    Artem Temos
    Keymaster

    Hello,

    We will review this before the next update. Thank you.

    Regards

Viewing 2 posts - 1 through 2 (of 2 total)