WC_Helper_Orders_API::create_order()
Core function to create an order on WooCommerce.com. Pings the API and catches the exceptions if any.
Метод класса: WC_Helper_Orders_API{}
Хуков нет.
Возвращает
WP_REST_Response
.
Использование
$result = WC_Helper_Orders_API::create_order( $request );
- $request(WP_REST_Request) (обязательный)
- Request object.
Код WC_Helper_Orders_API::create_order() WC Helper Orders API::create order WC 9.4.2
public static function create_order( $request ) { if ( ! current_user_can( 'install_plugins' ) ) { return new \WP_REST_Response( array( 'message' => __( 'You do not have permission to install plugins.', 'woocommerce' ), ), 403 ); } try { $response = WC_Helper_API::post( 'create-order', array( 'authenticated' => true, 'body' => http_build_query( array( 'product_id' => $request['product_id'], ), ), ) ); return new \WP_REST_Response( json_decode( wp_remote_retrieve_body( $response ), true ), wp_remote_retrieve_response_code( $response ) ); } catch ( Exception $e ) { return new \WP_REST_Response( array( 'message' => __( 'Could not start the installation process. Reason: ', 'woocommerce' ) . $e->getMessage(), 'code' => 'could-not-install', ), 500 ); } }