WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WC_REST_Order_Refunds_V1_Controller::create_item() WC 1.0

Create a single item.

Это метод класса: WC_REST_Order_Refunds_V1_Controller

Хуки из метода
Возвращает

WP_Error/WP_REST_Response.

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

$WC_REST_Order_Refunds_V1_Controller = new WC_REST_Order_Refunds_V1_Controller();
$var = $WC_REST_Order_Refunds_V1_Controller->create_item( $request );
$request(WP_REST_Request) (обязательный)
Full details about the request.

Код WC REST Order Refunds V1 Controller::create item: woocommerce/includes/api/v1/class-wc-rest-order-refunds-controller.php WC 3.6.5

<?php
public function create_item( $request ) {
	if ( ! empty( $request['id'] ) ) {
		/* translators: %s: post type */
		return new WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) );
	}

	$order_data = get_post( (int) $request['order_id'] );

	if ( empty( $order_data ) ) {
		return new WP_Error( 'woocommerce_rest_invalid_order', __( 'Order is invalid', 'woocommerce' ), 400 );
	}

	if ( 0 > $request['amount'] ) {
		return new WP_Error( 'woocommerce_rest_invalid_order_refund', __( 'Refund amount must be greater than zero.', 'woocommerce' ), 400 );
	}

	// Create the refund.
	$refund = wc_create_refund( array(
		'order_id'       => $order_data->ID,
		'amount'         => $request['amount'],
		'reason'         => empty( $request['reason'] ) ? null : $request['reason'],
		'refund_payment' => is_bool( $request['api_refund'] ) ? $request['api_refund'] : true,
		'restock_items'  => true,
	) );

	if ( is_wp_error( $refund ) ) {
		return new WP_Error( 'woocommerce_rest_cannot_create_order_refund', $refund->get_error_message(), 500 );
	}

	if ( ! $refund ) {
		return new WP_Error( 'woocommerce_rest_cannot_create_order_refund', __( 'Cannot create order refund, please try again.', 'woocommerce' ), 500 );
	}

	$post = get_post( $refund->get_id() );
	$this->update_additional_fields_for_object( $post, $request );

	/**
	 * Fires after a single item is created or updated via the REST API.
	 *
	 * @param WP_Post         $post      Post object.
	 * @param WP_REST_Request $request   Request object.
	 * @param boolean         $creating  True when creating item, false when updating.
	 */
	do_action( "woocommerce_rest_insert_{$this->post_type}", $post, $request, true );

	$request->set_param( 'context', 'edit' );
	$response = $this->prepare_item_for_response( $post, $request );
	$response = rest_ensure_response( $response );
	$response->set_status( 201 );
	$response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID ) ) );

	return $response;
}