Automattic\WooCommerce\Internal\Admin\Orders\MetaBoxes

CustomMetaBox::handle_add_meta()privateWC 1.0

Part of WP Core's wp_ajax_add_meta. This is re-implemented to support updating meta for custom tables.

Метод класса: CustomMetaBox{}

No Hooks.

Return

null. Nothing.

Usage

// private - for code of main (parent) class only
$result = $this->handle_add_meta( $order, $meta_key, $meta_value );
$order(WC_Order) (required)
Order object.
$meta_key(string) (required)
Meta key.
$meta_value(string) (required)
Meta value.

Code of CustomMetaBox::handle_add_meta() WC 7.1.0

private function handle_add_meta( WC_Order $order, string $meta_key, string $meta_value ) {
	$order_data_store = WC_Data_Store::load( 'order' );
	$count            = 0;
	if ( is_protected_meta( $meta_key ) ) {
		wp_send_json_error( 'protected_meta' );
		wp_die();
	}
	$meta_id  = $order_data_store->add_meta(
		$order,
		new WC_Meta_Data(
			array(
				'key'   => $meta_key,
				'value' => $meta_value,
			)
		)
	);
	$response = new WP_Ajax_Response(
		array(
			'what'     => 'meta',
			'id'       => $meta_id,
			'data'     => $this->list_meta_row(
				array(
					'meta_id'    => $meta_id,
					'meta_key'   => $meta_key, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- false positive, not a meta query.
					'meta_value' => $meta_value, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- false positive, not a meta query.
				),
				$count
			),
			'position' => 1,
		)
	);
	$response->send();
}