WC_Post_Data::update_post_metadata()
Ensure floats are correctly converted to strings based on PHP locale.
Метод класса: WC_Post_Data{}
Хуков нет.
Возвращает
null|true|false
.
Использование
$result = WC_Post_Data::update_post_metadata( $check, $object_id, $meta_key, $meta_value, $prev_value );
- $check(null) (обязательный)
- Whether to allow updating metadata for the given type.
- $object_id(int) (обязательный)
- Object ID.
- $meta_key(строка) (обязательный)
- Meta key.
- $meta_value(разное) (обязательный)
- Meta value. Must be serializable if non-scalar.
- $prev_value(разное) (обязательный)
- If specified, only update existing metadata entries with the specified value. Otherwise, update all entries.
Код WC_Post_Data::update_post_metadata() WC Post Data::update post metadata WC 9.4.2
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; }