Remove _wc_save_product_price
This commit is contained in:
parent
aa2ce1a1cc
commit
8a78cc212b
|
@ -2029,17 +2029,9 @@ class WC_AJAX {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( $variations as $variation_id ) {
|
foreach ( $variations as $variation_id ) {
|
||||||
// Price fields
|
$variation = wc_get_product( $variation_id );
|
||||||
$regular_price = wc_clean( $data['value'] );
|
$variation->save_regular_price( wc_clean( $data['value'] ) );
|
||||||
$sale_price = get_post_meta( $variation_id, '_sale_price', true );
|
$variation->save();
|
||||||
|
|
||||||
// Date fields
|
|
||||||
$date_from = get_post_meta( $variation_id, '_sale_price_dates_from', true );
|
|
||||||
$date_to = get_post_meta( $variation_id, '_sale_price_dates_to', true );
|
|
||||||
$date_from = ! empty( $date_from ) ? date( 'Y-m-d', $date_from ) : '';
|
|
||||||
$date_to = ! empty( $date_to ) ? date( 'Y-m-d', $date_to ) : '';
|
|
||||||
|
|
||||||
_wc_save_product_price( $variation_id, $regular_price, $sale_price, $date_from, $date_to );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2056,17 +2048,9 @@ class WC_AJAX {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( $variations as $variation_id ) {
|
foreach ( $variations as $variation_id ) {
|
||||||
// Price fields
|
$variation = wc_get_product( $variation_id );
|
||||||
$regular_price = get_post_meta( $variation_id, '_regular_price', true );
|
$variation->save_sale_price( wc_clean( $data['value'] ) );
|
||||||
$sale_price = wc_clean( $data['value'] );
|
$variation->save();
|
||||||
|
|
||||||
// Date fields
|
|
||||||
$date_from = get_post_meta( $variation_id, '_sale_price_dates_from', true );
|
|
||||||
$date_to = get_post_meta( $variation_id, '_sale_price_dates_to', true );
|
|
||||||
$date_from = ! empty( $date_from ) ? date( 'Y-m-d', $date_from ) : '';
|
|
||||||
$date_to = ! empty( $date_to ) ? date( 'Y-m-d', $date_to ) : '';
|
|
||||||
|
|
||||||
_wc_save_product_price( $variation_id, $regular_price, $sale_price, $date_from, $date_to );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2187,27 +2171,17 @@ class WC_AJAX {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( $variations as $variation_id ) {
|
foreach ( $variations as $variation_id ) {
|
||||||
// Price fields
|
$variation = wc_get_product( $variation_id );
|
||||||
$regular_price = get_post_meta( $variation_id, '_regular_price', true );
|
|
||||||
$sale_price = get_post_meta( $variation_id, '_sale_price', true );
|
|
||||||
|
|
||||||
// Date fields
|
if ( 'false' !== $data['date_from'] ) {
|
||||||
$date_from = get_post_meta( $variation_id, '_sale_price_dates_from', true );
|
$variation->set_date_on_sale_from( wc_clean( $data['date_from']) );
|
||||||
$date_to = get_post_meta( $variation_id, '_sale_price_dates_to', true );
|
|
||||||
|
|
||||||
if ( 'false' === $data['date_from'] ) {
|
|
||||||
$date_from = ! empty( $date_from ) ? date( 'Y-m-d', $date_from ) : '';
|
|
||||||
} else {
|
|
||||||
$date_from = $data['date_from'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 'false' === $data['date_to'] ) {
|
if ( 'false' !== $data['date_to'] ) {
|
||||||
$date_to = ! empty( $date_to ) ? date( 'Y-m-d', $date_to ) : '';
|
$variation->set_date_on_sale_from( wc_clean( $data['date_to']) );
|
||||||
} else {
|
|
||||||
$date_to = $data['date_to'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_wc_save_product_price( $variation_id, $regular_price, $sale_price, $date_from, $date_to );
|
$variation->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2259,28 +2233,25 @@ class WC_AJAX {
|
||||||
* Bulk action - Set Price.
|
* Bulk action - Set Price.
|
||||||
* @access private
|
* @access private
|
||||||
* @used-by bulk_edit_variations
|
* @used-by bulk_edit_variations
|
||||||
* @param array $variations
|
* @param array $variations
|
||||||
* @param string $operator + or -
|
* @param string $operator + or -
|
||||||
* @param string $field price being adjusted
|
* @param string $field price being adjusted _regular_price or _sale_price
|
||||||
* @param string $value Price or Percent
|
* @param string $value Price or Percent
|
||||||
*/
|
*/
|
||||||
private static function variation_bulk_adjust_price( $variations, $field, $operator, $value ) {
|
private static function variation_bulk_adjust_price( $variations, $field, $operator, $value ) {
|
||||||
foreach ( $variations as $variation_id ) {
|
foreach ( $variations as $variation_id ) {
|
||||||
// Get existing data
|
$variation = wc_get_product( $variation_id );
|
||||||
$_regular_price = get_post_meta( $variation_id, '_regular_price', true );
|
$field_value = $variation->{"get$field"}( 'edit' );
|
||||||
$_sale_price = get_post_meta( $variation_id, '_sale_price', true );
|
|
||||||
$date_from = get_post_meta( $variation_id, '_sale_price_dates_from', true );
|
|
||||||
$date_to = get_post_meta( $variation_id, '_sale_price_dates_to', true );
|
|
||||||
$date_from = ! empty( $date_from ) ? date( 'Y-m-d', $date_from ) : '';
|
|
||||||
$date_to = ! empty( $date_to ) ? date( 'Y-m-d', $date_to ) : '';
|
|
||||||
|
|
||||||
if ( '%' === substr( $value, -1 ) ) {
|
if ( '%' === substr( $value, -1 ) ) {
|
||||||
$percent = wc_format_decimal( substr( $value, 0, -1 ) );
|
$percent = wc_format_decimal( substr( $value, 0, -1 ) );
|
||||||
$$field += ( ( $$field / 100 ) * $percent ) * "{$operator}1";
|
$field_value += ( ( $field_value / 100 ) * $percent ) * "{$operator}1";
|
||||||
} else {
|
} else {
|
||||||
$$field += $value * "{$operator}1";
|
$field_value += $value * "{$operator}1";
|
||||||
}
|
}
|
||||||
_wc_save_product_price( $variation_id, $_regular_price, $_sale_price, $date_from, $date_to );
|
|
||||||
|
$variation->{"set$field"}( $field_value );
|
||||||
|
$variation->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -732,3 +732,56 @@ function woocommerce_get_product_schema() {
|
||||||
|
|
||||||
return 'http://schema.org/' . $schema;
|
return 'http://schema.org/' . $schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save product price.
|
||||||
|
*
|
||||||
|
* This is a private function (internal use ONLY) used until a data manipulation api is built.
|
||||||
|
*
|
||||||
|
* @since 2.4.0
|
||||||
|
* @todo needed?
|
||||||
|
*
|
||||||
|
* @param int $product_id
|
||||||
|
* @param float $regular_price
|
||||||
|
* @param float $sale_price
|
||||||
|
* @param string $date_from
|
||||||
|
* @param string $date_to
|
||||||
|
*/
|
||||||
|
function _wc_save_product_price( $product_id, $regular_price, $sale_price = '', $date_from = '', $date_to = '' ) {
|
||||||
|
_doing_it_wrong( '_wc_save_product_price()', 'This function is not for developer use and is deprecated.', '2.7' );
|
||||||
|
|
||||||
|
$product_id = absint( $product_id );
|
||||||
|
$regular_price = wc_format_decimal( $regular_price );
|
||||||
|
$sale_price = '' === $sale_price ? '' : wc_format_decimal( $sale_price );
|
||||||
|
$date_from = wc_clean( $date_from );
|
||||||
|
$date_to = wc_clean( $date_to );
|
||||||
|
|
||||||
|
update_post_meta( $product_id, '_regular_price', $regular_price );
|
||||||
|
update_post_meta( $product_id, '_sale_price', $sale_price );
|
||||||
|
|
||||||
|
// Save Dates
|
||||||
|
update_post_meta( $product_id, '_sale_price_dates_from', $date_from ? strtotime( $date_from ) : '' );
|
||||||
|
update_post_meta( $product_id, '_sale_price_dates_to', $date_to ? strtotime( $date_to ) : '' );
|
||||||
|
|
||||||
|
if ( $date_to && ! $date_from ) {
|
||||||
|
$date_from = strtotime( 'NOW', current_time( 'timestamp' ) );
|
||||||
|
update_post_meta( $product_id, '_sale_price_dates_from', $date_from );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update price if on sale
|
||||||
|
if ( '' !== $sale_price && '' === $date_to && '' === $date_from ) {
|
||||||
|
update_post_meta( $product_id, '_price', $sale_price );
|
||||||
|
} else {
|
||||||
|
update_post_meta( $product_id, '_price', $regular_price );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( '' !== $sale_price && $date_from && strtotime( $date_from ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
|
||||||
|
update_post_meta( $product_id, '_price', $sale_price );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $date_to && strtotime( $date_to ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
|
||||||
|
update_post_meta( $product_id, '_price', $regular_price );
|
||||||
|
update_post_meta( $product_id, '_sale_price_dates_from', '' );
|
||||||
|
update_post_meta( $product_id, '_sale_price_dates_to', '' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -716,57 +716,6 @@ function wc_get_product_id_by_sku( $sku ) {
|
||||||
return ( $product_id ) ? intval( $product_id ) : 0;
|
return ( $product_id ) ? intval( $product_id ) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Save product price.
|
|
||||||
*
|
|
||||||
* This is a private function (internal use ONLY) used until a data manipulation api is built.
|
|
||||||
*
|
|
||||||
* @since 2.4.0
|
|
||||||
* @todo needed?
|
|
||||||
*
|
|
||||||
* @param int $product_id
|
|
||||||
* @param float $regular_price
|
|
||||||
* @param float $sale_price
|
|
||||||
* @param string $date_from
|
|
||||||
* @param string $date_to
|
|
||||||
*/
|
|
||||||
function _wc_save_product_price( $product_id, $regular_price, $sale_price = '', $date_from = '', $date_to = '' ) {
|
|
||||||
$product_id = absint( $product_id );
|
|
||||||
$regular_price = wc_format_decimal( $regular_price );
|
|
||||||
$sale_price = '' === $sale_price ? '' : wc_format_decimal( $sale_price );
|
|
||||||
$date_from = wc_clean( $date_from );
|
|
||||||
$date_to = wc_clean( $date_to );
|
|
||||||
|
|
||||||
update_post_meta( $product_id, '_regular_price', $regular_price );
|
|
||||||
update_post_meta( $product_id, '_sale_price', $sale_price );
|
|
||||||
|
|
||||||
// Save Dates
|
|
||||||
update_post_meta( $product_id, '_sale_price_dates_from', $date_from ? strtotime( $date_from ) : '' );
|
|
||||||
update_post_meta( $product_id, '_sale_price_dates_to', $date_to ? strtotime( $date_to ) : '' );
|
|
||||||
|
|
||||||
if ( $date_to && ! $date_from ) {
|
|
||||||
$date_from = strtotime( 'NOW', current_time( 'timestamp' ) );
|
|
||||||
update_post_meta( $product_id, '_sale_price_dates_from', $date_from );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update price if on sale
|
|
||||||
if ( '' !== $sale_price && '' === $date_to && '' === $date_from ) {
|
|
||||||
update_post_meta( $product_id, '_price', $sale_price );
|
|
||||||
} else {
|
|
||||||
update_post_meta( $product_id, '_price', $regular_price );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( '' !== $sale_price && $date_from && strtotime( $date_from ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
|
|
||||||
update_post_meta( $product_id, '_price', $sale_price );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $date_to && strtotime( $date_to ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
|
|
||||||
update_post_meta( $product_id, '_price', $regular_price );
|
|
||||||
update_post_meta( $product_id, '_sale_price_dates_from', '' );
|
|
||||||
update_post_meta( $product_id, '_sale_price_dates_to', '' );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get attibutes/data for an individual variation from the database and maintain it's integrity.
|
* Get attibutes/data for an individual variation from the database and maintain it's integrity.
|
||||||
* @since 2.4.0
|
* @since 2.4.0
|
||||||
|
|
Loading…
Reference in New Issue