Checkout logic
This commit is contained in:
@@ -22,6 +22,59 @@ function wiaas_api_notice($message, $code, $data = null) {
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates REST API notice responses with wc error notices
|
||||
*
|
||||
* @param array|null $data
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
function wiaas_api_cart_error_notices($data = null) {
|
||||
return wiaas_api_cart_notices('error', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates REST API notice responses with wc warning notices
|
||||
*
|
||||
* @param array|null $data
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
function wiaas_api_cart_warning_notices($data = null) {
|
||||
return wiaas_api_cart_notices('notice', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates REST API notice responses with wc notices
|
||||
*
|
||||
* @param string $types Notice types (error, success)
|
||||
* @param array|null $data
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
function wiaas_api_cart_notices($types, $data = null) {
|
||||
|
||||
$types = is_array($types) ? $types : array( $types );
|
||||
|
||||
$messages = array();
|
||||
foreach ($types as $type) {
|
||||
$messages = array_merge($messages, wc_get_notices($type));
|
||||
}
|
||||
wc_clear_notices();
|
||||
|
||||
$messages = array_map(function($message) {
|
||||
return array(
|
||||
'code' => 'error',
|
||||
'message' => $message
|
||||
);
|
||||
}, $messages);
|
||||
|
||||
return rest_ensure_response(array(
|
||||
'messages' => $messages,
|
||||
'data' => $data
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate REST API error
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user