WC_AJAX::add_order_item()public staticWC 1.0

Add order item via ajax. Used on the edit order screen in WP Admin.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

$result = WC_AJAX::add_order_item();

Код WC_AJAX::add_order_item() WC 9.4.2

public static function add_order_item() {
	check_ajax_referer( 'order-item', 'security' );

	if ( ! current_user_can( 'edit_shop_orders' ) ) {
		wp_die( -1 );
	}

	if ( ! isset( $_POST['order_id'] ) ) {
		throw new Exception( __( 'Invalid order', 'woocommerce' ) );
	}
	$order_id = absint( wp_unslash( $_POST['order_id'] ) );

	// If we passed through items it means we need to save first before adding a new one.
	$items = ( ! empty( $_POST['items'] ) ) ? wp_unslash( $_POST['items'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized

	$items_to_add = isset( $_POST['data'] ) ? array_filter( wp_unslash( (array) $_POST['data'] ) ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized

	try {
		$response = self::maybe_add_order_item( $order_id, $items, $items_to_add );
		wp_send_json_success( $response );
	} catch ( Exception $e ) {
		wp_send_json_error( array( 'error' => $e->getMessage() ) );
	}
}