WC_Helper_Subscriptions_API::disconnect()public staticWC 1.0

Disconnect a WooCommerce.com subscription.

Метод класса: WC_Helper_Subscriptions_API{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$result = WC_Helper_Subscriptions_API::disconnect( $request );
$request(WP_REST_Request) (обязательный)
Request object.

Код WC_Helper_Subscriptions_API::disconnect() WC 9.4.2

public static function disconnect( $request ) {
	$product_key = $request->get_param( 'product_key' );
	try {
		$success = WC_Helper::deactivate_helper_subscription( $product_key );
	} catch ( Exception $e ) {
		wp_send_json_error(
			array(
				'message' => $e->getMessage(),
			),
			400
		);
	}
	if ( $success ) {
		wp_send_json_success(
			array(
				'message' => __( 'Your subscription has been disconnected.', 'woocommerce' ),
			)
		);
	} else {
		wp_send_json_error(
			array(
				'message' => __( 'There was an error disconnecting your subscription. Please try again.', 'woocommerce' ),
			),
			400
		);
	}
}