Automattic\WooCommerce\Internal\Admin\Orders\MetaBoxes

CustomMetaBox::handle_update_meta()privateWC 1.0

Handles updating metadata.

{} It's a method of the class: CustomMetaBox{}

No Hooks.

Return

null. Nothing.

Usage

// private - for code of main (parent) class only
$result = $this->handle_update_meta( $order, $meta );
$order(WC_Order) (required)
Order object.
$meta(array) (required)
Meta object to update.

Code of CustomMetaBox::handle_update_meta() WC 7.1.0

private function handle_update_meta( WC_Order $order, array $meta ) {
	if ( ! is_array( $meta ) ) {
		wp_send_json_error( 'invalid_meta' );
		wp_die();
	}
	array_walk( $meta, 'sanitize_text_field' );
	$mid = (int) key( $meta );
	if ( ! $mid ) {
		wp_send_json_error( 'invalid_meta_id' );
		wp_die();
	}
	$key   = $meta[ $mid ]['key'];
	$value = $meta[ $mid ]['value'];
	if ( is_protected_meta( $key ) ) {
		wp_send_json_error( 'protected_meta' );
		wp_die();
	}
	if ( '' === trim( $key ) ) {
		wp_send_json_error( 'invalid_meta_key' );
		wp_die();
	}

	$order_data_store = WC_Data_Store::load( 'order' );
	$count            = 0;
	$meta_object      = new WC_Meta_Data(
		array(
			'id'    => $mid,
			'key'   => $key,
			'value' => $value,
		)
	);
	$order_data_store->update_meta( $order, $meta_object );
	$response = new WP_Ajax_Response(
		array(
			'what'     => 'meta',
			'id'       => $mid,
			'old_id'   => $mid,
			'data'     => $this->list_meta_row(
				array(
					'meta_key'   => $key, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- false positive, not a meta query.
					'meta_value' => $value, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- false positive, not a meta query.
					'meta_id'    => $mid,
				),
				$count
			),
			'position' => 0,
		)
	);
	$response->send();
}