Automattic\WooCommerce\Internal\Orders

OrderAttributionController::enqueue_scripts_and_styles()privateWC 1.0

Scripts & styles for custom source tracking and cart tracking.

Method of the class: OrderAttributionController{}

Return

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->enqueue_scripts_and_styles();

OrderAttributionController::enqueue_scripts_and_styles() code WC 9.3.3

private function enqueue_scripts_and_styles() {
	wp_enqueue_script(
		'sourcebuster-js',
		plugins_url( "assets/js/sourcebuster/sourcebuster{$this->get_script_suffix()}.js", WC_PLUGIN_FILE ),
		array(),
		Constants::get_constant( 'WC_VERSION' ),
		true
	);

	wp_enqueue_script(
		'wc-order-attribution',
		plugins_url( "assets/js/frontend/order-attribution{$this->get_script_suffix()}.js", WC_PLUGIN_FILE ),
		// Technically we do depend on 'wp-data', 'wc-blocks-checkout' for blocks checkout,
		// but as implementing conditional dependency on the server-side would be too complex,
		// we resolve this condition at the client-side.
		array( 'sourcebuster-js' ),
		Constants::get_constant( 'WC_VERSION' ),
		true
	);

	/**
	 * Filter the lifetime of the cookie used for source tracking.
	 *
	 * @since 8.5.0
	 *
	 * @param float $lifetime The lifetime of the Sourcebuster cookies in months.
	 *
	 * The default value forces Sourcebuster into making the cookies valid for the current session only.
	 */
	$lifetime = (float) apply_filters( 'wc_order_attribution_cookie_lifetime_months', 0.00001 );

	/**
	 * Filter the session length for source tracking.
	 *
	 * @since 8.5.0
	 *
	 * @param int $session_length The session length in minutes.
	 */
	$session_length = (int) apply_filters( 'wc_order_attribution_session_length_minutes', 30 );

	/**
	 * Filter to enable base64 encoding for cookie values.
	 *
	 * @since 9.0.0
	 *
	 * @param bool $use_base64_cookies True to enable base64 encoding, default is false.
	 */
	$use_base64_cookies = apply_filters( 'wc_order_attribution_use_base64_cookies', false );

	/**
	 * Filter to allow tracking.
	 *
	 * @since 8.5.0
	 *
	 * @param bool $allow_tracking True to allow tracking, false to disable.
	 */
	$allow_tracking = wc_bool_to_string( apply_filters( 'wc_order_attribution_allow_tracking', true ) );

	// Create Order Attribution JS namespace with parameters.
	$namespace = array(
		'params' => array(
			'lifetime'      => $lifetime,
			'session'       => $session_length,
			'base64'        => $use_base64_cookies,
			'ajaxurl'       => admin_url( 'admin-ajax.php' ),
			'prefix'        => $this->field_prefix,
			'allowTracking' => 'yes' === $allow_tracking,
		),
		'fields' => $this->fields,
	);

	wp_localize_script( 'wc-order-attribution', 'wc_order_attribution', $namespace );
}