WC_Helper_Admin::get_connection_urlpublic staticWC 1.0

Generates the URL for connecting or disconnecting the store to/from WooCommerce.com. Approach taken from existing helper code that isn't exposed.

Method of the class: WC_Helper_Admin{}

No Hooks.

Returns

String.

Usage

$result = WC_Helper_Admin::get_connection_url( $reconnect );
$reconnect(true|false)
indicate if the site is being reconnected.
Default: false

WC_Helper_Admin::get_connection_url() code WC 10.4.3

public static function get_connection_url( $reconnect = false ) {
	// Default to wc-addons, although this can be changed from the frontend
	// in the function `connectUrl()` within marketplace functions.tsx.
	$connect_url_args = array(
		'page'    => 'wc-addons',
		'section' => 'helper',
	);

	// No active connection.
	if ( WC_Helper::is_site_connected() && ! $reconnect ) {
		$connect_url_args['wc-helper-disconnect'] = 1;
		$connect_url_args['wc-helper-nonce']      = wp_create_nonce( 'disconnect' );
	} else {
		$connect_url_args['wc-helper-connect'] = 1;
		$connect_url_args['wc-helper-nonce']   = wp_create_nonce( 'connect' );
	}

	if ( ! empty( $_GET['utm_source'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$connect_url_args['utm_source'] = wc_clean( wp_unslash( $_GET['utm_source'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
	}

	if ( ! empty( $_GET['utm_campaign'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$connect_url_args['utm_campaign'] = wc_clean( wp_unslash( $_GET['utm_campaign'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
	}

	return add_query_arg(
		$connect_url_args,
		admin_url( 'admin.php' )
	);
}