WC_Frontend_Scripts::load_scripts │ public static │ WC 1.0
Register/queue frontend scripts.
Method of the class: WC_Frontend_Scripts{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = WC_Frontend_Scripts::load_scripts();
WC_Frontend_Scripts::load_scripts() WC Frontend Scripts::load scripts code WC 10.8.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_account_page() ) {
self::enqueue_script( 'wc-account-i18n' );
}
if ( is_checkout() ) {
self::enqueue_script( 'wc-checkout' );
}
if ( wc_string_to_bool( get_option( 'woocommerce_address_autocomplete_enabled', 'no' ) ) === true ) {
$address_provider_service = wc_get_container()->get( AddressProviderController::class );
if ( $address_provider_service && method_exists( $address_provider_service, 'get_providers' ) ) {
$registered_providers = $address_provider_service->get_providers();
if ( is_array( $registered_providers ) && count( $registered_providers ) > 0 ) {
// Always enqueue the common module if providers are registered.
self::enqueue_script( 'wc-address-autocomplete-common' );
self::enqueue_script( 'wc-address-autocomplete' );
self::enqueue_style( 'wc-address-autocomplete' );
}
}
}
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() && ! wp_is_block_theme() ) || ( ! empty( $post->post_content ) && strstr( $post->post_content, '[product_page' ) ) ) {
if ( current_theme_supports( 'wc-product-gallery-zoom' ) ) {
self::enqueue_script( 'wc-zoom' );
}
if ( current_theme_supports( 'wc-product-gallery-slider' ) ) {
self::enqueue_script( 'wc-flexslider' );
}
if ( current_theme_supports( 'wc-product-gallery-lightbox' ) ) {
self::enqueue_script( 'wc-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 (
DefaultCustomerAddress::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; }' );
}
}