Support » Plugin: Product Filter by WooBeWoo » Filter by Height and Width

  • Resolved jordanwebdev

    (@jordanwebdev)


    Is there a way to filter by the product’s height and width, with the ability to set min and max values?

    If not, how would you suggest I go about adding this functionality in with code?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter jordanwebdev

    (@jordanwebdev)

    I tried the following but it only works when there are no WooBeWoo filters selected. This is in a pre_get_posts action function I created.

    $min_width = $_GET['width_min'] ?? false;
    $max_width = $_GET['width_max'] ?? false;
    if ($min_width !== false && $max_width !== false) {
      $width_query = array(
        'key' => '_width',
        'compare' => 'BETWEEN',
        'value' => array(intval($min_width), intval($max_width)),
        'type' => 'NUMERIC',
      );
      array_push($meta_query, $width_query);
    
      $query->set( 'meta_query', $meta_query );
    }
    • This reply was modified 1 year, 1 month ago by jordanwebdev.
    • This reply was modified 1 year, 1 month ago by jordanwebdev.
    • This reply was modified 1 year, 1 month ago by jordanwebdev.
    Thread Starter jordanwebdev

    (@jordanwebdev)

    Not sure if this is related.

    Undefined variable $keyData (woo-product-filter/modules/meta/models/meta.php:164). This error happens on the shop page even when no filters are selected.

    Thread Starter jordanwebdev

    (@jordanwebdev)

    Got it working with the following. I added a form for this on the front end, which submits values that are retrieved here using $_GET.

    Of course it would be nice if this was a part of the plugin :).

    Note that I’m using decimal casting because sometimes a value of 0 was set for the height/width, which is incorrect. So I used 0.01 instead of 0 for the min.

    add_filter('get_meta_sql','cast_decimal_precision');
    function cast_decimal_precision( $array ) {
      $array['where'] = str_replace('DECIMAL','DECIMAL(10,3)',$array['where']);
      return $array;
    }
    // Width Query
        $min_width = $_GET['width_min'] ?? false;
        $max_width = $_GET['width_max'] ?? false;
        if ($min_width !== false && $max_width !== false) {
          $min = intval($min_width) === 0 ? 0.01 : $min_width;
          $width_query = array(
            'key' => '_width',
            'value' => array($min, intval($max_width)),
            'compare' => 'BETWEEN',
            'type' => 'DECIMAL',
          );
          $meta_query[] = $width_query;
        }
    
        // Height Query
        $min_height = $_GET['height_min'] ?? false;
        $max_height = $_GET['height_max'] ?? false;
        if ($min_height !== false && $max_height !== false) {
          $min = intval($min_height) === 0 ? 0.01 : $min_height;
          $height_query = array(
            'key' => '_height',
            'value' => array($min, intval($max_height)),
            'compare' => 'BETWEEN',
            'type' => 'DECIMAL',
          );
          $meta_query[] = $height_query;
        }
    Plugin Author Nick McReynolds

    (@woobewoo)

    Hello @jordanwebdev,

    Thank you for your hard work and feedback.
    Similar functionality can be obtained using the WooCommerce Product Filter by WooBeWoo plugin PRO version.

    To do this, you need to create an attribute filter based on meta data: https://woobewoo.com/documentation/filter-by-custom-meta-field/

    And then select the “Slider” display form: https://woobewoo.com/documentation/attribute-filter-settings/

    This way you get a meta data filter with max and min values.

    Thread Starter jordanwebdev

    (@jordanwebdev)

    Awesome. Does that $49 1 site license plan include unlimited updates?

    Plugin Author Nick McReynolds

    (@woobewoo)

    Unfortunately, it is forbidden to discuss paid content on this site, please contact our support team: https://woobewoo.com/contact-us/

    buddyfinn

    (@buddyfinn)

    Hey Jordan,
    I’m looking to have the same functionality as you. Did this plugin work for you?

    Thread Starter jordanwebdev

    (@jordanwebdev)

    I didn’t update to pro. Ended up creating my own custom functionality (see above). I created my own custom form for dimensions below the filters.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Filter by Height and Width’ is closed to new replies.