WC_Frontend_Scripts::load_scripts()public staticWC 1.0

Register/queue frontend scripts.

Method of the class: WC_Frontend_Scripts{}

No Hooks.

Return

null. Nothing (null).

Usage

$result = WC_Frontend_Scripts::load_scripts();

WC_Frontend_Scripts::load_scripts() code WC 8.6.1

public static function load_scripts() {
	global $post;

	if ( ! did_action( 'before_woocommerce_init' ) ) {
		return;
	}

	self::register_scripts();
	self::register_styles();

	if ( 'yes' === get_option( 'woocommerce_enable_ajax_add_to_cart' ) ) {
		self::enqueue_script( 'wc-add-to-cart' );
	}
	if ( is_cart() ) {
		self::enqueue_script( 'wc-cart' );
	}
	if ( is_cart() || is_checkout() || is_account_page() ) {
		self::enqueue_script( 'selectWoo' );
		self::enqueue_style( 'select2' );

		// Password strength meter. Load in checkout, account login and edit account page.
		if ( ( 'no' === get_option( 'woocommerce_registration_generate_password' ) && ! is_user_logged_in() ) || is_edit_account_page() || is_lost_password_page() ) {
			self::enqueue_script( 'wc-password-strength-meter' );
		}
	}
	if ( is_checkout() ) {
		self::enqueue_script( 'wc-checkout' );
	}
	if ( is_add_payment_method_page() ) {
		self::enqueue_script( 'wc-add-payment-method' );
	}
	if ( is_lost_password_page() ) {
		self::enqueue_script( 'wc-lost-password' );
	}

	// Load gallery scripts on product pages only if supported.
	if ( is_product() || ( ! empty( $post->post_content ) && strstr( $post->post_content, '[product_page' ) ) ) {
		if ( current_theme_supports( 'wc-product-gallery-zoom' ) ) {
			self::enqueue_script( 'zoom' );
		}
		if ( current_theme_supports( 'wc-product-gallery-slider' ) ) {
			self::enqueue_script( 'flexslider' );
		}
		if ( current_theme_supports( 'wc-product-gallery-lightbox' ) ) {
			self::enqueue_script( 'photoswipe-ui-default' );
			self::enqueue_style( 'photoswipe-default-skin' );
			add_action( 'wp_footer', 'woocommerce_photoswipe' );
		}
		self::enqueue_script( 'wc-single-product' );
	}

	// Only enqueue the geolocation script if the Default Current Address is set to "Geolocate
	// (with Page Caching Support) and outside of the cart, checkout, account and customizer preview.
	if (
		'geolocation_ajax' === get_option( 'woocommerce_default_customer_address' )
		&& ! ( is_cart() || is_account_page() || is_checkout() || is_customize_preview() )
	) {
		$ua = strtolower( wc_get_user_agent() ); // Exclude common bots from geolocation by user agent.

		if ( ! strstr( $ua, 'bot' ) && ! strstr( $ua, 'spider' ) && ! strstr( $ua, 'crawl' ) ) {
			self::enqueue_script( 'wc-geolocation' );
		}
	}

	// Global frontend scripts.
	self::enqueue_script( 'woocommerce' );

	// CSS Styles.
	$enqueue_styles = self::get_styles();
	if ( $enqueue_styles ) {
		foreach ( $enqueue_styles as $handle => $args ) {
			if ( ! isset( $args['has_rtl'] ) ) {
				$args['has_rtl'] = false;
			}

			self::enqueue_style( $handle, $args['src'], $args['deps'], $args['version'], $args['media'], $args['has_rtl'] );
		}
	}

	// Placeholder style.
	wp_register_style( 'woocommerce-inline', false ); // phpcs:ignore
	wp_enqueue_style( 'woocommerce-inline' );

	if ( true === wc_string_to_bool( get_option( 'woocommerce_checkout_highlight_required_fields', 'yes' ) ) ) {
		wp_add_inline_style( 'woocommerce-inline', '.woocommerce form .form-row .required { visibility: visible; }' );
	} else {
		wp_add_inline_style( 'woocommerce-inline', '.woocommerce form .form-row .required { visibility: hidden; }' );
	}
}