WordPress at Your Fingertips
function is not described

WC_REST_CRUD_Controller::save_object() protected WC 3.0.0

Save an object data.

{} It's a method of the class: WC_REST_CRUD_Controller{}

No Hooks.

Return

WC_Data|WP_Error.

Usage

// protected - for code of main (parent) or child class
$result = $this->save_object( $request, $creating );
$request(WP_REST_Request) (required)
Full details about the request.
$creating(true|false)
If is creating a new object.
Default: false

Changelog

Since 3.0.0 Introduced.

Code of WC_REST_CRUD_Controller::save_object() WC 5.9.0

protected function save_object( $request, $creating = false ) {
	try {
		$object = $this->prepare_object_for_database( $request, $creating );

		if ( is_wp_error( $object ) ) {
			return $object;
		}

		$object->save();

		return $this->get_object( $object->get_id() );
	} catch ( WC_Data_Exception $e ) {
		return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
	} catch ( WC_REST_Exception $e ) {
		return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
	}
}