Automattic\WooCommerce\Internal\Admin\Orders\MetaBoxes

CustomMetaBox::delete_meta_ajax()publicWC 1.0

Reimplementation of WP core's wp_ajax_delete_meta method to support order custom meta updates with custom tables.

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

Хуков нет.

Возвращает

null. Ничего.

Использование

$CustomMetaBox = new CustomMetaBox();
$CustomMetaBox->delete_meta_ajax();

Код CustomMetaBox::delete_meta_ajax() WC 6.9.4

public function delete_meta_ajax() {
	$meta_id  = (int) $_POST['id'] ?? 0;
	$order_id = (int) $_POST['order_id'] ?? 0;
	if ( ! $meta_id || ! $order_id ) {
		wp_send_json_error( 'invalid_meta_id' );
		wp_die();
	}
	check_ajax_referer( "delete-meta_$meta_id" );

	$order          = $this->verify_order_edit_permission_for_ajax( $order_id );
	$meta_to_delete = wp_list_filter( $order->get_meta_data(), array( 'id' => $meta_id ) );

	if ( empty( $meta_to_delete ) ) {
		wp_send_json_error( 'invalid_meta_id' );
		wp_die();
	}

	$order->delete_meta_data_by_mid( $meta_id );
	if ( $order->save() ) {
		wp_die( 1 );
	}
	wp_die( 0 );
}