WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WC_Admin_Post_Types::set_new_price() private WC 1.0

Set the new regular or sale price if requested.

Это метод класса: WC_Admin_Post_Types{}

Хуков нет.

Возвращает

true/false. true if a new price has been set, false otherwise.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->set_new_price( $product, $price_type );
$product(WC_Product) (обязательный)
The product to set the new price for.
$price_type(строка) (обязательный)
'regular' or 'sale'.

Код WC Admin Post Types::set new price: woocommerce/includes/admin/class-wc-admin-post-types.php WC 4.5.2

<?php
private function set_new_price( $product, $price_type ) {
	// phpcs:disable WordPress.Security.NonceVerification.Recommended

	$request_data = $this->request_data();

	if ( empty( $request_data[ "change_{$price_type}_price" ] ) || ! isset( $request_data[ "_{$price_type}_price" ] ) ) {
		return false;
	}

	$old_price     = $product->{"get_{$price_type}_price"}();
	$price_changed = false;

	$change_price  = absint( $request_data[ "change_{$price_type}_price" ] );
	$raw_price     = wc_clean( wp_unslash( $request_data[ "_{$price_type}_price" ] ) );
	$is_percentage = (bool) strstr( $raw_price, '%' );
	$price         = wc_format_decimal( $raw_price );

	switch ( $change_price ) {
		case 1:
			$new_price = $price;
			break;
		case 2:
			if ( $is_percentage ) {
				$percent   = $price / 100;
				$new_price = $old_price + ( $old_price * $percent );
			} else {
				$new_price = $old_price + $price;
			}
			break;
		case 3:
			if ( $is_percentage ) {
				$percent   = $price / 100;
				$new_price = max( 0, $old_price - ( $old_price * $percent ) );
			} else {
				$new_price = max( 0, $old_price - $price );
			}
			break;
		case 4:
			if ( 'sale' !== $price_type ) {
				break;
			}
			$regular_price = $product->get_regular_price();
			if ( $is_percentage ) {
				$percent   = $price / 100;
				$new_price = max( 0, $regular_price - ( round( $regular_price * $percent, wc_get_price_decimals() ) ) );
			} else {
				$new_price = max( 0, $regular_price - $price );
			}
			break;

		default:
			break;
	}

	if ( isset( $new_price ) && $new_price !== $old_price ) {
		$price_changed = true;
		$new_price     = round( $new_price, wc_get_price_decimals() );
		$product->{"set_{$price_type}_price"}( $new_price );
	}

	return $price_changed;

	// phpcs:disable WordPress.Security.NonceVerification.Recommended
}