Skip to content

Commit

Permalink
Fix for product meta lookup table incorrectly marking a product as on…
Browse files Browse the repository at this point in the history
…sale Closes #43008 (#43011)

* Update wc-product-functions.php

Determine if a product is on sale based on regular price, which is how its done in the WC_Product class https://github.com/woocommerce/woocommerce/blob/7122669d448acb90d0f8a7177b76baaccec2e76b/plugins/woocommerce/includes/abstracts/abstract-wc-product.php#L1633

* Add changefile(s) from automation for the following project(s): woocommerce

* added missing placeholders

* Update 43011-patch-1

* Add changefile(s) from automation for the following project(s): woocommerce

* Re-trigger CI

---------

Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Jorge A. Torres <jorge.torres@automattic.com>
  • Loading branch information
3 people committed Mar 1, 2024
1 parent e8b633f commit bf84ed5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/43011-patch-1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Use regular_price to determine if product is not sale and don't rely only on price for product_meta_lookup
4 changes: 4 additions & 0 deletions plugins/woocommerce/includes/wc-product-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1562,14 +1562,18 @@ function wc_update_product_lookup_tables_column( $column ) {
{$wpdb->wc_product_meta_lookup} lookup_table
LEFT JOIN {$wpdb->postmeta} meta1 ON lookup_table.product_id = meta1.post_id AND meta1.meta_key = '_price'
LEFT JOIN {$wpdb->postmeta} meta2 ON lookup_table.product_id = meta2.post_id AND meta2.meta_key = '_sale_price'
LEFT JOIN {$wpdb->postmeta} meta3 ON lookup_table.product_id = meta3.post_id AND meta3.meta_key = '_regular_price'
SET
lookup_table.`{$column}` = IF (
CAST( meta1.meta_value AS DECIMAL ) >= 0
AND CAST( meta2.meta_value AS CHAR ) != ''
AND CAST( meta1.meta_value AS DECIMAL( 10, %d ) ) = CAST( meta2.meta_value AS DECIMAL( 10, %d ) )
AND CAST( meta3.meta_value AS DECIMAL( 10, %d ) ) > CAST( meta2.meta_value AS DECIMAL( 10, %d ) )
, 1, 0 )
",
$decimals,
$decimals,
$decimals,
$decimals
)
);
Expand Down

0 comments on commit bf84ed5

Please sign in to comment.