WC_Post_Data::update_post_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.
Return Return
(null|bool)
Source Source
File: includes/class-wc-post-data.php
public static function update_post_metadata( $check, $object_id, $meta_key, $meta_value, $prev_value ) { // Delete product cache if someone uses meta directly. if ( in_array( get_post_type( $object_id ), array( 'product', 'product_variation' ), true ) ) { wp_cache_delete( 'product-' . $object_id, 'products' ); } if ( ! empty( $meta_value ) && is_float( $meta_value ) && ! registered_meta_key_exists( 'post', $meta_key ) && in_array( get_post_type( $object_id ), array_merge( wc_get_order_types(), array( 'shop_coupon', 'product', 'product_variation' ) ), true ) ) { // Convert float to string. $meta_value = wc_float_to_string( $meta_value ); // Update meta value with new string. update_metadata( 'post', $object_id, $meta_key, $meta_value, $prev_value ); return true; } return $check; }