/**
  * Register/queue frontend scripts.
  */
 public static function load_scripts()
 {
     global $post;
     if (!did_action('before_woocommerce_init')) {
         return;
     }
     $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
     $lightbox_en = 'yes' === get_option('woocommerce_enable_lightbox');
     $ajax_cart_en = 'yes' === get_option('woocommerce_enable_ajax_add_to_cart');
     $assets_path = str_replace(array('http:', 'https:'), '', WC()->plugin_url()) . '/assets/';
     $frontend_script_path = $assets_path . 'js/frontend/';
     // Register any scripts for later use, or used as dependencies
     self::register_script('select2', $assets_path . 'js/select2/select2' . $suffix . '.js', array('jquery'), '3.5.4');
     self::register_script('jquery-blockui', $assets_path . 'js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array('jquery'), '2.70');
     self::register_script('jquery-payment', $assets_path . 'js/jquery-payment/jquery.payment' . $suffix . '.js', array('jquery'), '1.4.1');
     self::register_script('jquery-cookie', $assets_path . 'js/jquery-cookie/jquery.cookie' . $suffix . '.js', array('jquery'), '1.4.1');
     self::register_script('wc-credit-card-form', $frontend_script_path . 'credit-card-form' . $suffix . '.js', array('jquery', 'jquery-payment'));
     self::register_script('wc-add-to-cart-variation', $frontend_script_path . 'add-to-cart-variation' . $suffix . '.js', array('jquery', 'wp-util'));
     self::register_script('wc-single-product', $frontend_script_path . 'single-product' . $suffix . '.js', array('jquery'));
     self::register_script('wc-country-select', $frontend_script_path . 'country-select' . $suffix . '.js', array('jquery'));
     self::register_script('wc-address-i18n', $frontend_script_path . 'address-i18n' . $suffix . '.js', array('jquery'));
     self::register_script('wc-password-strength-meter', $frontend_script_path . 'password-strength-meter' . $suffix . '.js', array('jquery', 'password-strength-meter'));
     // Register frontend scripts conditionally
     if ($ajax_cart_en) {
         self::enqueue_script('wc-add-to-cart', $frontend_script_path . 'add-to-cart' . $suffix . '.js');
     }
     if (is_cart()) {
         self::enqueue_script('wc-cart', $frontend_script_path . 'cart' . $suffix . '.js', array('jquery', 'wc-country-select', 'wc-address-i18n'));
     }
     if (is_checkout() || is_account_page()) {
         self::enqueue_script('select2');
         self::enqueue_style('select2', $assets_path . 'css/select2.css');
         // 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()) {
             self::enqueue_script('wc-password-strength-meter');
         }
     }
     if (is_checkout()) {
         self::enqueue_script('wc-checkout', $frontend_script_path . 'checkout' . $suffix . '.js', array('jquery', 'woocommerce', 'wc-country-select', 'wc-address-i18n'));
     }
     if (is_add_payment_method_page()) {
         self::enqueue_script('wc-add-payment-method', $frontend_script_path . 'add-payment-method' . $suffix . '.js', array('jquery', 'woocommerce'));
     }
     if (is_lost_password_page()) {
         self::enqueue_script('wc-lost-password', $frontend_script_path . 'lost-password' . $suffix . '.js', array('jquery', 'woocommerce'));
     }
     if ($lightbox_en && (is_product() || !empty($post->post_content) && strstr($post->post_content, '[product_page'))) {
         self::enqueue_script('prettyPhoto', $assets_path . 'js/prettyPhoto/jquery.prettyPhoto' . $suffix . '.js', array('jquery'), '3.1.6', true);
         self::enqueue_script('prettyPhoto-init', $assets_path . 'js/prettyPhoto/jquery.prettyPhoto.init' . $suffix . '.js', array('jquery', 'prettyPhoto'));
         self::enqueue_style('woocommerce_prettyPhoto_css', $assets_path . 'css/prettyPhoto.css');
     }
     if (is_product()) {
         self::enqueue_script('wc-single-product');
     }
     if ('geolocation_ajax' === get_option('woocommerce_default_customer_address')) {
         // Exclude common bots from geolocation by user agent.
         $ua = wc_get_user_agent();
         if (!strstr($ua, 'bot') && !strstr($ua, 'spider') && !strstr($ua, 'crawl')) {
             self::enqueue_script('wc-geolocation', $frontend_script_path . 'geolocation' . $suffix . '.js', array('jquery'));
         }
     }
     // Global frontend scripts
     self::enqueue_script('woocommerce', $frontend_script_path . 'woocommerce' . $suffix . '.js', array('jquery', 'jquery-blockui'));
     self::enqueue_script('wc-cart-fragments', $frontend_script_path . 'cart-fragments' . $suffix . '.js', array('jquery', 'jquery-cookie'));
     // CSS Styles
     if ($enqueue_styles = self::get_styles()) {
         foreach ($enqueue_styles as $handle => $args) {
             self::enqueue_style($handle, $args['src'], $args['deps'], $args['version'], $args['media']);
         }
     }
 }
示例#2
0
 public static function is_edit_account_page()
 {
     return self::exists() && is_edit_account_page();
 }
 /**
  * Register/queue frontend scripts.
  */
 public static function load_scripts()
 {
     global $post;
     if (!did_action('before_woocommerce_init')) {
         return;
     }
     $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
     $ajax_cart_en = 'yes' === get_option('woocommerce_enable_ajax_add_to_cart');
     $assets_path = str_replace(array('http:', 'https:'), '', WC()->plugin_url()) . '/assets/';
     $frontend_script_path = $assets_path . 'js/frontend/';
     // Register any scripts for later use, or used as dependencies
     self::register_script('select2', $assets_path . 'js/select2/select2' . $suffix . '.js', array('jquery'), '3.5.4');
     self::register_script('jquery-blockui', $assets_path . 'js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array('jquery'), '2.70');
     self::register_script('jquery-payment', $assets_path . 'js/jquery-payment/jquery.payment' . $suffix . '.js', array('jquery'), '1.4.1');
     self::register_script('js-cookie', $assets_path . 'js/js-cookie/js.cookie' . $suffix . '.js', array(), '2.1.3');
     self::register_script('wc-credit-card-form', $frontend_script_path . 'credit-card-form' . $suffix . '.js', array('jquery', 'jquery-payment'));
     self::register_script('wc-add-to-cart-variation', $frontend_script_path . 'add-to-cart-variation' . $suffix . '.js', array('jquery', 'wp-util'));
     self::register_script('wc-single-product', $frontend_script_path . 'single-product' . $suffix . '.js', array('jquery'));
     self::register_script('wc-country-select', $frontend_script_path . 'country-select' . $suffix . '.js', array('jquery'));
     self::register_script('wc-address-i18n', $frontend_script_path . 'address-i18n' . $suffix . '.js', array('jquery'));
     self::register_script('wc-password-strength-meter', $frontend_script_path . 'password-strength-meter' . $suffix . '.js', array('jquery', 'password-strength-meter'));
     // Register frontend scripts conditionally
     if ($ajax_cart_en) {
         self::enqueue_script('wc-add-to-cart', $frontend_script_path . 'add-to-cart' . $suffix . '.js');
     }
     if (is_cart()) {
         self::enqueue_script('wc-cart', $frontend_script_path . 'cart' . $suffix . '.js', array('jquery', 'wc-country-select', 'wc-address-i18n'));
     }
     if (is_checkout() || is_account_page()) {
         self::enqueue_script('select2');
         self::enqueue_style('select2', $assets_path . 'css/select2.css');
         // 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', $frontend_script_path . 'checkout' . $suffix . '.js', array('jquery', 'woocommerce', 'wc-country-select', 'wc-address-i18n'));
     }
     if (is_add_payment_method_page()) {
         self::enqueue_script('wc-add-payment-method', $frontend_script_path . 'add-payment-method' . $suffix . '.js', array('jquery', 'woocommerce'));
     }
     if (is_lost_password_page()) {
         self::enqueue_script('wc-lost-password', $frontend_script_path . 'lost-password' . $suffix . '.js', array('jquery', 'woocommerce'));
     }
     if (is_product() || !empty($post->post_content) && strstr($post->post_content, '[product_page')) {
         self::enqueue_script('flexslider', $assets_path . 'js/flexslider/jquery.flexslider' . $suffix . '.js', array('jquery'), '2.7.0', true);
         self::enqueue_script('photoswipe', $assets_path . 'js/photoswipe/photoswipe' . $suffix . '.js', '4.1.1', true);
         self::enqueue_script('photoswipe-ui-default', $assets_path . 'js/photoswipe/photoswipe-ui-default' . $suffix . '.js', array('photoswipe'), '4.1.1', true);
         self::enqueue_style('photoswipe', $assets_path . 'css/photoswipe/photoswipe.css');
         self::enqueue_style('photoswipe-default-skin', $assets_path . 'css/photoswipe/default-skin/default-skin.css');
         self::enqueue_script('zoom', $assets_path . 'js/zoom/jquery.zoom' . $suffix . '.js', array('jquery'), '1.7.15', true);
         self::enqueue_script('wc-single-product');
         wp_localize_script('wc-single-product', 'flexslider_options', apply_filters('woocommerce_single_product_carousel_options', array('rtl' => is_rtl(), 'animation' => 'slide', 'smoothHeight' => true, 'directionNav' => false, 'controlNav' => 'thumbnails', 'slideshow' => false, 'animationSpeed' => 500)));
     }
     if ('geolocation_ajax' === get_option('woocommerce_default_customer_address')) {
         // Exclude common bots from geolocation by user agent.
         $ua = wc_get_user_agent();
         if (!strstr($ua, 'bot') && !strstr($ua, 'spider') && !strstr($ua, 'crawl')) {
             self::enqueue_script('wc-geolocation', $frontend_script_path . 'geolocation' . $suffix . '.js', array('jquery'));
         }
     }
     // Global frontend scripts
     self::enqueue_script('woocommerce', $frontend_script_path . 'woocommerce' . $suffix . '.js', array('jquery', 'jquery-blockui', 'js-cookie'));
     self::enqueue_script('wc-cart-fragments', $frontend_script_path . 'cart-fragments' . $suffix . '.js', array('jquery', 'js-cookie'));
     // CSS Styles
     if ($enqueue_styles = self::get_styles()) {
         foreach ($enqueue_styles as $handle => $args) {
             self::enqueue_style($handle, $args['src'], $args['deps'], $args['version'], $args['media']);
         }
     }
     // These are deprecated scripts only included for BW compatibility. @todo remove in future version.
     self::register_script('jquery-cookie', $assets_path . 'js/jquery-cookie/jquery.cookie' . $suffix . '.js', array('jquery'), '1.4.1');
     self::register_script('prettyPhoto', $assets_path . 'js/prettyPhoto/jquery.prettyPhoto' . $suffix . '.js', array('jquery'), '3.1.6', true);
     self::register_script('prettyPhoto-init', $assets_path . 'js/prettyPhoto/jquery.prettyPhoto.init' . $suffix . '.js', array('jquery', 'prettyPhoto'));
     self::register_style('woocommerce_prettyPhoto_css', $assets_path . 'css/prettyPhoto.css');
 }
 /**
  * Register/queue frontend scripts.
  */
 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_checkout() || is_account_page()) {
         self::enqueue_script('select2');
         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');
     }
     if (is_product() || !empty($post->post_content) && strstr($post->post_content, '[product_page')) {
         self::enqueue_script('flexslider');
         self::enqueue_script('photoswipe-ui-default');
         self::enqueue_style('photoswipe-default-skin');
         self::enqueue_script('zoom');
         self::enqueue_script('wc-single-product');
     }
     if ('geolocation_ajax' === get_option('woocommerce_default_customer_address')) {
         $ua = 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');
     self::enqueue_script('wc-cart-fragments');
     // CSS Styles
     if ($enqueue_styles = self::get_styles()) {
         foreach ($enqueue_styles as $handle => $args) {
             self::enqueue_style($handle, $args['src'], $args['deps'], $args['version'], $args['media']);
         }
     }
 }