WC_Post_Data::update_order_item_metadata( null $check, int $object_id, string $meta_key, mixed $meta_value, mixed $prev_value )

Ensure floats are correctly converted to strings based on PHP locale.


Description Description


Parameters Parameters

$check

(Required) Whether to allow updating metadata for the given type.

$object_id

(Required) Object ID.

$meta_key

(Required) Meta key.

$meta_value

(Required) Meta value. Must be serializable if non-scalar.

$prev_value

(Required) If specified, only update existing metadata entries with the specified value. Otherwise, update all entries.


Top ↑

Return Return

(null|bool)


Top ↑

Source Source

File: includes/class-wc-post-data.php

	public static function update_order_item_metadata( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
		if ( ! empty( $meta_value ) && is_float( $meta_value ) ) {

			// Convert float to string.
			$meta_value = wc_float_to_string( $meta_value );

			// Update meta value with new string.
			update_metadata( 'order_item', $object_id, $meta_key, $meta_value, $prev_value );

			return true;
		}
		return $check;
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.