Automattic\WooCommerce\Blocks

BlockPatterns::update_ai_connection_allowed_option()publicWC 1.0

Make sure the 'woocommerce_blocks_allow_ai_connection' option is set to true if the site is connected to AI.

Method of the class: BlockPatterns{}

No Hooks.

Return

true|false.

Usage

$BlockPatterns = new BlockPatterns();
$BlockPatterns->update_ai_connection_allowed_option( $option, $value ): bool;
$option(string) (required)
The option name.
$value(string) (required)
The option value.

BlockPatterns::update_ai_connection_allowed_option() code WC 8.9.0

public function update_ai_connection_allowed_option( $option, $value ): bool {
	$ai_connection = new Connection();

	$site_id = $ai_connection->get_site_id();

	if ( is_wp_error( $site_id ) ) {
		return update_option( 'woocommerce_blocks_allow_ai_connection', false );
	}

	$token = $ai_connection->get_jwt_token( $site_id );

	if ( is_wp_error( $token ) ) {
		return update_option( 'woocommerce_blocks_allow_ai_connection', false );
	}

	return update_option( 'woocommerce_blocks_allow_ai_connection', true );
}