From 218aebd3292c7a7f06c658a292422c6e1fb48c69 Mon Sep 17 00:00:00 2001 From: Diego Zanella Date: Mon, 11 Dec 2017 17:08:53 +0000 Subject: [PATCH] Legacy API - Use "edit" context when setting product prices Ensured that the "edit" context is used when checking if the product is on sale, like it's done when fetching product's regular and sale prices. This prevents price filters from running and, potentially, altering the prices set via the API. * Ref. https://github.com/woocommerce/woocommerce/issues/17125 * Ref. https://github.com/woocommerce/woocommerce/commit/6e5cdc60e8a2b80520e73f1871c12bfc377fd420 --- includes/api/legacy/v2/class-wc-api-products.php | 2 +- includes/api/legacy/v3/class-wc-api-products.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/api/legacy/v2/class-wc-api-products.php b/includes/api/legacy/v2/class-wc-api-products.php index 661e4219678..895e207d7d1 100644 --- a/includes/api/legacy/v2/class-wc-api-products.php +++ b/includes/api/legacy/v2/class-wc-api-products.php @@ -1077,7 +1077,7 @@ class WC_API_Products extends WC_API_Resource { $product->set_date_on_sale_to( $date_to ); $product->set_date_on_sale_from( $date_from ); - if ( $product->is_on_sale() ) { + if ( $product->is_on_sale( 'edit' ) ) { $product->set_price( $product->get_sale_price( 'edit' ) ); } else { $product->set_price( $product->get_regular_price( 'edit' ) ); diff --git a/includes/api/legacy/v3/class-wc-api-products.php b/includes/api/legacy/v3/class-wc-api-products.php index e6e64d47ea0..cab36e34152 100644 --- a/includes/api/legacy/v3/class-wc-api-products.php +++ b/includes/api/legacy/v3/class-wc-api-products.php @@ -1567,7 +1567,7 @@ class WC_API_Products extends WC_API_Resource { $product->set_date_on_sale_to( $date_to ); $product->set_date_on_sale_from( $date_from ); - if ( $product->is_on_sale() ) { + if ( $product->is_on_sale( 'edit' ) ) { $product->set_price( $product->get_sale_price( 'edit' ) ); } else { $product->set_price( $product->get_regular_price( 'edit' ) );