Skip to content

get_lowest_price_array uses NUMERIC (integer cast) — price comparison broken for decimal prices #44

@lukelocksmith

Description

@lukelocksmith

Bug description

get_lowest_price_array() in class-iworks-omnibus-post-type-price-log.php uses 'type' => 'NUMERIC' in its meta_query. In WordPress, NUMERIC maps to CAST(meta_value AS SIGNED) in MySQL, which truncates decimal values to integers.

This causes the != comparison (used to exclude the current sale price) to never work for non-integer prices:

-- What happens with NUMERIC (SIGNED):
CAST("29.98" AS SIGNED) = 29
29 != 29.98 → TRUE  -- should be FALSE!

-- What should happen with DECIMAL(10,2):
CAST("29.98" AS DECIMAL(10,2)) = 29.98
29.98 != 29.98 → FALSE  -- correct

Result

The current sale price is never excluded from the "lowest price" query. The plugin shows the current promotional price as the "previous lowest price" instead of the actual lowest price before the discount.

Additional issue

woocommerce_wp_text_input_price() only displays price_sale from the result array. When the missing setting is set to regular and there's no sale history, the fallback returns price (regular price) but without price_sale key — so the admin always shows "no data" for products that never had a sale.

Steps to reproduce

  1. Create a simple product with regular price 29.99, no sale price
  2. Save product
  3. Set sale price to 29.98, save
  4. Check Omnibus Directive fields in admin → shows 29.98 (wrong, should show 29.99)

Expected behavior

Omnibus should show 29.99 (the lowest price from 30 days before the discount was introduced).

Suggested fix

Change 'type' => 'NUMERIC' to 'type' => 'DECIMAL(10,2)' in the meta_query inside get_lowest_price_array().

Workaround

We created a companion plugin that fixes this via filters (no modifications to Omnibus files):
https://github.com/lukelocksmith/omnibus-fix

Environment

  • Omnibus version: 3.0.4
  • WordPress: 6.7
  • WooCommerce: 9.x
  • PHP: 8.x
  • MySQL: 8.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions