Automattic\WooCommerce\Internal\Admin\Orders\MetaBoxes
CustomMetaBox::add_meta_ajax()
Reimplementation of WP core's wp_ajax_add_meta method to support order custom meta updates with custom tables.
Method of the class: CustomMetaBox{}
No Hooks.
Return
null
. Nothing (null).
Usage
$CustomMetaBox = new CustomMetaBox(); $CustomMetaBox->add_meta_ajax();
CustomMetaBox::add_meta_ajax() CustomMetaBox::add meta ajax code WC 9.6.0
public function add_meta_ajax() { if ( ! check_ajax_referer( 'add-meta', '_ajax_nonce-add-meta' ) ) { wp_send_json_error( 'invalid_nonce' ); wp_die(); } $order_id = (int) $_POST['order_id'] ?? 0; $order = $this->verify_order_edit_permission_for_ajax( $order_id ); $select_meta_key = trim( sanitize_text_field( wp_unslash( $_POST['metakeyselect'] ?? '' ) ) ); $input_meta_key = trim( sanitize_text_field( wp_unslash( $_POST['metakeyinput'] ?? '' ) ) ); if ( empty( $_POST['meta'] ) && in_array( $select_meta_key, array( '', '#NONE#' ), true ) && ! $input_meta_key ) { wp_die( 1 ); } if ( ! empty( $_POST['meta'] ) ) { // update. $meta = wp_unslash( $_POST['meta'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- sanitization done below in array_walk. $this->handle_update_meta( $order, $meta ); } else { // add meta. $meta_value = sanitize_text_field( wp_unslash( $_POST['metavalue'] ?? '' ) ); $meta_key = $input_meta_key ? $input_meta_key : $select_meta_key; $this->handle_add_meta( $order, $meta_key, $meta_value ); } }