WC_Helper_Subscriptions_API::connect
Connect a WooCommerce.com subscription.
Метод класса: WC_Helper_Subscriptions_API{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$result = WC_Helper_Subscriptions_API::connect( $request );
- $request(WP_REST_Request) (обязательный)
- Request object.
Код WC_Helper_Subscriptions_API::connect() WC Helper Subscriptions API::connect WC 10.5.0
public static function connect( $request ) {
$product_key = $request->get_param( 'product_key' );
try {
$success = WC_Helper::activate_helper_subscription( $product_key );
} catch ( Exception $e ) {
$error_data = array(
'message' => $e->getMessage(),
);
if ( $e instanceof WC_Data_Exception ) {
$error_data['code'] = $e->getErrorCode();
// Include extra data from the exception so the client can render contextual UI (e.g. maxed out sites list).
$error_data['data'] = $e->getErrorData();
$status_code = (int) $e->getCode();
if ( 100 > $status_code || 599 < $status_code ) {
$status_code = 400;
}
} else {
$status_code = 400;
}
wp_send_json_error( $error_data, $status_code );
}
if ( $success ) {
wp_send_json_success(
array(
'message' => __( 'Your subscription has been connected.', 'woocommerce' ),
)
);
} else {
wp_send_json_error(
array(
'message' => __( 'There was an error connecting your subscription. Please try again.', 'woocommerce' ),
),
400
);
}
}