WC_Helper_Subscriptions_API::set_auto_update │ public static │ WC 1.0

Turn auto-updates on or off for a subscription's installed plugin or theme.

Method of the class: WC_Helper_Subscriptions_API{}

No Hooks.

Returns

void. Nothing (null).

Usage

$result = WC_Helper_Subscriptions_API::set_auto_update( $request ): void;
$request(required)
.

WC_Helper_Subscriptions_API::set_auto_update() code WC 11.2.1

public static function set_auto_update( $request ): void {
	if ( ! current_user_can( 'update_plugins' ) && ! current_user_can( 'update_themes' ) ) {
		wp_send_json_error(
			array(
				'message' => __( 'Sorry, you are not allowed to modify plugins or themes.', 'woocommerce' ),
			),
			403
		);
	}

	try {
		WC_Helper::set_subscription_auto_update( $request->get_param( 'product_key' ), (bool) $request->get_param( 'enabled' ) );
	} catch ( Exception $e ) {
		wp_send_json_error(
			array(
				'message' => $e->getMessage(),
			),
			400
		);
	}

	wp_send_json_success(
		array(
			'message' => $request->get_param( 'enabled' )
				? __( 'Auto-updates are now on for this product.', 'woocommerce' )
				: __( 'Auto-updates are now off for this product.', 'woocommerce' ),
		)
	);
}