WC_AJAX::variation_bulk_adjust_price()private staticWC 1.0

Bulk action - Set Price.

Method of the class: WC_AJAX{}

No Hooks.

Return

null. Nothing (null).

Usage

$result = WC_AJAX::variation_bulk_adjust_price( $variations, $field, $operator, $value );
$variations(array) (required)
List of variations.
$field(string) (required)
price being adjusted _regular_price or _sale_price.
$operator(string) (required)
+ or -.
$value(string) (required)
Price or Percent.

WC_AJAX::variation_bulk_adjust_price() code WC 8.7.0

private static function variation_bulk_adjust_price( $variations, $field, $operator, $value ) {
	foreach ( $variations as $variation_id ) {
		$variation   = wc_get_product( $variation_id );
		$field_value = $variation->{"get_$field"}( 'edit' );

		if ( '%' === substr( $value, -1 ) ) {
			$percent      = wc_format_decimal( substr( $value, 0, -1 ) );
			$field_value += NumberUtil::round( ( $field_value / 100 ) * $percent, wc_get_price_decimals() ) * "{$operator}1";
		} else {
			$field_value += $value * "{$operator}1";
		}

		$variation->{"set_$field"}( $field_value );
		$variation->save();
	}
}