WordPress at Your Fingertips
function is not described

WC_REST_Coupons_V1_Controller::save_coupon() protected WC 3.0.0

Saves a coupon to the database.

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

No Hooks.

Return

WP_Error|Int.

Usage

// protected - for code of main (parent) or child class
$result = $this->save_coupon( $request );
$request(WP_REST_Request) (required)
Full details about the request.

Changelog

Since 3.0.0 Introduced.

Code of WC_REST_Coupons_V1_Controller::save_coupon() WC 5.9.0

protected function save_coupon( $request ) {
	try {
		$coupon = $this->prepare_item_for_database( $request );

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

		$coupon->save();
		return $coupon->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() ) );
	}
}