WC_AJAX::variation_bulk_adjust_price
Bulk action - Set Price.
Method of the class: WC_AJAX{}
No Hooks.
Returns
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() WC AJAX::variation bulk adjust price code WC 10.8.1
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' );
// Skip variations without a price set
if ( '' === $field_value || null === $field_value ) {
continue;
}
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();
}
}