Feature requests

show related product base on last category �

2y agoPending

in woodmart show related product base on first category, even if we have some sub category related product change to unrelated product 😊 please fix it and base on last category selected , related product show.

and 16 others

1 comment

  1. Woodmart’s related products widget currently uses the first product category, which can result in irrelevant item suggestions.

    I would like to propose the following enhancements:

    1. Use the deepest (latest) category assigned to the product; fallback to parent category.

    2. Include price range matching (e.g. ±20% around current product price or configurable).

    3. Add a toggle control to:

    - Show only in‑stock products

    - Or include out‑of‑stock/backorder items

    4. Allow per‑product or global enable/disable via Customizer or product‑level metabox.

    5. Provide developer filters/hooks such as:

    - `woodmart_related_query_args($args, $product_id)`

    - `woodmart_show_related_section($show, $product_id)`

    6. Implement caching for query results (e.g. via `transient_set/get`) for performance.

    7. Ensure compatibility with WPML, SEO plugins, and related‑product plugins like WebToffee :contentReference[oaicite:22]{index=22}.

    **Benefits:**

    - More contextually relevant suggestions → higher conversion rates

    - Flexible configuration and smarter UX

    - Lightweight queries with performance safety

    - Values developer customization and compatibility with popular plugins

    Technical Details

    Category detection:

    $cats = wp_get_post_terms($product_id, 'product_cat');

    $deepest = select_deepest($cats);

    if (!$deepest) $deepest = fallback($cats);

    Price filtering:

    $price = get_post_meta($product_id, '_price', true);

    $min = $price * (1 - $price_delta);

    $max = $price * (1 + $price_delta);

    $args['meta_query'][] = ['key'=>'_price','value'=>[$min,$max],'compare'=>'BETWEEN','type'=>'NUMERIC'];

    Stock filtering:

    if ($instock_only) {

    $args['meta_query'][] = ['key'=>'_stock_status','value'=>'instock'];

    }

    Extensible hooks:

    $args = apply_filters('woodmart_related_query_args', $args, $product_id);

    $show = apply_filters('woodmart_show_related_section', true, $product_id);

    Caching example:

    $transient_key = 'wd_related_' . $product_id;

    $related = get_transient($transient_key);

    if (!$related) {

    $related = new WP_Query($args);

    set_transient($transient_key, $related, HOUR_IN_SECONDS);

    }