WC_Frontend_Scripts

WC_Frontend_Scripts Class.

Defined (1)

The class is defined in the following location(s).

/includes/class-wc-frontend-scripts.php  
  1. class WC_Frontend_Scripts { 
  2.  
  3. /** 
  4. * Contains an array of script handles registered by WC. 
  5. * @var array 
  6. */ 
  7. private static $scripts = array(); 
  8.  
  9. /** 
  10. * Contains an array of script handles registered by WC. 
  11. * @var array 
  12. */ 
  13. private static $styles = array(); 
  14.  
  15. /** 
  16. * Contains an array of script handles localized by WC. 
  17. * @var array 
  18. */ 
  19. private static $wp_localize_scripts = array(); 
  20.  
  21. /** 
  22. * Hook in methods. 
  23. */ 
  24. public static function init() { 
  25. add_action( 'wp_enqueue_scripts', array( __CLASS__, 'load_scripts' ) ); 
  26. add_action( 'wp_print_scripts', array( __CLASS__, 'localize_printed_scripts' ), 5 ); 
  27. add_action( 'wp_print_footer_scripts', array( __CLASS__, 'localize_printed_scripts' ), 5 ); 
  28. add_action( 'setup_theme', array( __CLASS__, 'add_default_theme_support' ) ); 
  29.  
  30. /** 
  31. * Add theme support for default WP themes. 
  32. * @since 3.0.0 
  33. */ 
  34. public static function add_default_theme_support() { 
  35. if ( in_array( get_option( 'template' ), wc_get_core_supported_themes() ) ) { 
  36. add_theme_support( 'wc-product-gallery-zoom' ); 
  37. add_theme_support( 'wc-product-gallery-lightbox' ); 
  38. add_theme_support( 'wc-product-gallery-slider' ); 
  39.  
  40. /** 
  41. * Get styles for the frontend. 
  42. * @return array 
  43. */ 
  44. public static function get_styles() { 
  45. return apply_filters( 'woocommerce_enqueue_styles', array( 
  46. 'woocommerce-layout' => array( 
  47. 'src' => self::get_asset_url( 'assets/css/woocommerce-layout.css' ),  
  48. 'deps' => '',  
  49. 'version' => WC_VERSION,  
  50. 'media' => 'all',  
  51. 'has_rtl' => true,  
  52. ),  
  53. 'woocommerce-smallscreen' => array( 
  54. 'src' => self::get_asset_url( 'assets/css/woocommerce-smallscreen.css' ),  
  55. 'deps' => 'woocommerce-layout',  
  56. 'version' => WC_VERSION,  
  57. 'media' => 'only screen and (max-width: ' . apply_filters( 'woocommerce_style_smallscreen_breakpoint', $breakpoint = '768px' ) . ')',  
  58. 'has_rtl' => true,  
  59. ),  
  60. 'woocommerce-general' => array( 
  61. 'src' => self::get_asset_url( 'assets/css/woocommerce.css' ),  
  62. 'deps' => '',  
  63. 'version' => WC_VERSION,  
  64. 'media' => 'all',  
  65. 'has_rtl' => true,  
  66. ),  
  67. ) ); 
  68.  
  69. /** 
  70. * Return protocol relative asset URL. 
  71. * @param string $path 
  72. */ 
  73. private static function get_asset_url( $path ) { 
  74. return str_replace( array( 'http:', 'https:' ), '', plugins_url( $path, WC_PLUGIN_FILE ) ); 
  75.  
  76. /** 
  77. * Register a script for use. 
  78. * @uses wp_register_script() 
  79. * @access private 
  80. * @param string $handle 
  81. * @param string $path 
  82. * @param string[] $deps 
  83. * @param string $version 
  84. * @param boolean $in_footer 
  85. */ 
  86. private static function register_script( $handle, $path, $deps = array( 'jquery' ), $version = WC_VERSION, $in_footer = true ) { 
  87. self::$scripts[] = $handle; 
  88. wp_register_script( $handle, $path, $deps, $version, $in_footer ); 
  89.  
  90. /** 
  91. * Register and enqueue a script for use. 
  92. * @uses wp_enqueue_script() 
  93. * @access private 
  94. * @param string $handle 
  95. * @param string $path 
  96. * @param string[] $deps 
  97. * @param string $version 
  98. * @param boolean $in_footer 
  99. */ 
  100. private static function enqueue_script( $handle, $path = '', $deps = array( 'jquery' ), $version = WC_VERSION, $in_footer = true ) { 
  101. if ( ! in_array( $handle, self::$scripts ) && $path ) { 
  102. self::register_script( $handle, $path, $deps, $version, $in_footer ); 
  103. wp_enqueue_script( $handle ); 
  104.  
  105. /** 
  106. * Register a style for use. 
  107. * @uses wp_register_style() 
  108. * @access private 
  109. * @param string $handle 
  110. * @param string $path 
  111. * @param string[] $deps 
  112. * @param string $version 
  113. * @param string $media 
  114. * @param boolean $has_rtl 
  115. */ 
  116. private static function register_style( $handle, $path, $deps = array(), $version = WC_VERSION, $media = 'all', $has_rtl = false ) { 
  117. self::$styles[] = $handle; 
  118. wp_register_style( $handle, $path, $deps, $version, $media ); 
  119.  
  120. if ( $has_rtl ) { 
  121. wp_style_add_data( $handle, 'rtl', 'replace' ); 
  122.  
  123. /** 
  124. * Register and enqueue a styles for use. 
  125. * @uses wp_enqueue_style() 
  126. * @access private 
  127. * @param string $handle 
  128. * @param string $path 
  129. * @param string[] $deps 
  130. * @param string $version 
  131. * @param string $media 
  132. * @param boolean $has_rtl 
  133. */ 
  134. private static function enqueue_style( $handle, $path = '', $deps = array(), $version = WC_VERSION, $media = 'all', $has_rtl = false ) { 
  135. if ( ! in_array( $handle, self::$styles ) && $path ) { 
  136. self::register_style( $handle, $path, $deps, $version, $media, $has_rtl ); 
  137. wp_enqueue_style( $handle ); 
  138.  
  139. /** 
  140. * Register all WC scripts. 
  141. */ 
  142. private static function register_scripts() { 
  143. $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
  144. $register_scripts = array( 
  145. 'flexslider' => array( 
  146. 'src' => self::get_asset_url( 'assets/js/flexslider/jquery.flexslider' . $suffix . '.js' ),  
  147. 'deps' => array( 'jquery' ),  
  148. 'version' => '2.6.1',  
  149. ),  
  150. 'js-cookie' => array( 
  151. 'src' => self::get_asset_url( 'assets/js/js-cookie/js.cookie' . $suffix . '.js' ),  
  152. 'deps' => array(),  
  153. 'version' => '2.1.4',  
  154. ),  
  155. 'jquery-blockui' => array( 
  156. 'src' => self::get_asset_url( 'assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js' ),  
  157. 'deps' => array( 'jquery' ),  
  158. 'version' => '2.70',  
  159. ),  
  160. 'jquery-cookie' => array( // deprecated. 
  161. 'src' => self::get_asset_url( 'assets/js/jquery-cookie/jquery.cookie' . $suffix . '.js' ),  
  162. 'deps' => array( 'jquery' ),  
  163. 'version' => '1.4.1',  
  164. ),  
  165. 'jquery-payment' => array( 
  166. 'src' => self::get_asset_url( 'assets/js/jquery-payment/jquery.payment' . $suffix . '.js' ),  
  167. 'deps' => array( 'jquery' ),  
  168. 'version' => '1.4.1',  
  169. ),  
  170. 'photoswipe' => array( 
  171. 'src' => self::get_asset_url( 'assets/js/photoswipe/photoswipe' . $suffix . '.js' ),  
  172. 'deps' => array(),  
  173. 'version' => '4.1.1',  
  174. ),  
  175. 'photoswipe-ui-default' => array( 
  176. 'src' => self::get_asset_url( 'assets/js/photoswipe/photoswipe-ui-default' . $suffix . '.js' ),  
  177. 'deps' => array( 'photoswipe' ),  
  178. 'version' => '4.1.1',  
  179. ),  
  180. 'prettyPhoto' => array( // deprecated. 
  181. 'src' => self::get_asset_url( 'assets/js/prettyPhoto/jquery.prettyPhoto' . $suffix . '.js' ),  
  182. 'deps' => array( 'jquery' ),  
  183. 'version' => '3.1.6',  
  184. ),  
  185. 'prettyPhoto-init' => array( // deprecated. 
  186. 'src' => self::get_asset_url( 'assets/js/prettyPhoto/jquery.prettyPhoto.init' . $suffix . '.js' ),  
  187. 'deps' => array( 'jquery', 'prettyPhoto' ),  
  188. 'version' => WC_VERSION,  
  189. ),  
  190. 'select2' => array( 
  191. 'src' => self::get_asset_url( 'assets/js/select2/select2.full' . $suffix . '.js' ),  
  192. 'deps' => array( 'jquery' ),  
  193. 'version' => '4.0.3',  
  194. ),  
  195. 'wc-address-i18n' => array( 
  196. 'src' => self::get_asset_url( 'assets/js/frontend/address-i18n' . $suffix . '.js' ),  
  197. 'deps' => array( 'jquery' ),  
  198. 'version' => WC_VERSION,  
  199. ),  
  200. 'wc-add-payment-method' => array( 
  201. 'src' => self::get_asset_url( 'assets/js/frontend/add-payment-method' . $suffix . '.js' ),  
  202. 'deps' => array( 'jquery', 'woocommerce' ),  
  203. 'version' => WC_VERSION,  
  204. ),  
  205. 'wc-cart' => array( 
  206. 'src' => self::get_asset_url( 'assets/js/frontend/cart' . $suffix . '.js' ),  
  207. 'deps' => array( 'jquery', 'wc-country-select', 'wc-address-i18n' ),  
  208. 'version' => WC_VERSION,  
  209. ),  
  210. 'wc-cart-fragments' => array( 
  211. 'src' => self::get_asset_url( 'assets/js/frontend/cart-fragments' . $suffix . '.js' ),  
  212. 'deps' => array( 'jquery', 'js-cookie' ),  
  213. 'version' => WC_VERSION,  
  214. ),  
  215. 'wc-checkout' => array( 
  216. 'src' => self::get_asset_url( 'assets/js/frontend/checkout' . $suffix . '.js' ),  
  217. 'deps' => array( 'jquery', 'woocommerce', 'wc-country-select', 'wc-address-i18n' ),  
  218. 'version' => WC_VERSION,  
  219. ),  
  220. 'wc-country-select' => array( 
  221. 'src' => self::get_asset_url( 'assets/js/frontend/country-select' . $suffix . '.js' ),  
  222. 'deps' => array( 'jquery' ),  
  223. 'version' => WC_VERSION,  
  224. ),  
  225. 'wc-credit-card-form' => array( 
  226. 'src' => self::get_asset_url( 'assets/js/frontend/credit-card-form' . $suffix . '.js' ),  
  227. 'deps' => array( 'jquery', 'jquery-payment' ),  
  228. 'version' => WC_VERSION,  
  229. ),  
  230. 'wc-add-to-cart' => array( 
  231. 'src' => self::get_asset_url( 'assets/js/frontend/add-to-cart' . $suffix . '.js' ),  
  232. 'deps' => array( 'jquery' ),  
  233. 'version' => WC_VERSION,  
  234. ),  
  235. 'wc-add-to-cart-variation' => array( 
  236. 'src' => self::get_asset_url( 'assets/js/frontend/add-to-cart-variation' . $suffix . '.js' ),  
  237. 'deps' => array( 'jquery', 'wp-util' ),  
  238. 'version' => WC_VERSION,  
  239. ),  
  240. 'wc-geolocation' => array( 
  241. 'src' => self::get_asset_url( 'assets/js/frontend/geolocation' . $suffix . '.js' ),  
  242. 'deps' => array( 'jquery' ),  
  243. 'version' => WC_VERSION,  
  244. ),  
  245. 'wc-lost-password' => array( 
  246. 'src' => self::get_asset_url( 'assets/js/frontend/lost-password' . $suffix . '.js' ),  
  247. 'deps' => array( 'jquery', 'woocommerce' ),  
  248. 'version' => WC_VERSION,  
  249. ),  
  250. 'wc-password-strength-meter' => array( 
  251. 'src' => self::get_asset_url( 'assets/js/frontend/password-strength-meter' . $suffix . '.js' ),  
  252. 'deps' => array( 'jquery', 'password-strength-meter' ),  
  253. 'version' => WC_VERSION,  
  254. ),  
  255. 'wc-single-product' => array( 
  256. 'src' => self::get_asset_url( 'assets/js/frontend/single-product' . $suffix . '.js' ),  
  257. 'deps' => array( 'jquery' ),  
  258. 'version' => WC_VERSION,  
  259. ),  
  260. 'woocommerce' => array( 
  261. 'src' => self::get_asset_url( 'assets/js/frontend/woocommerce' . $suffix . '.js' ),  
  262. 'deps' => array( 'jquery', 'jquery-blockui', 'js-cookie' ),  
  263. 'version' => WC_VERSION,  
  264. ),  
  265. 'zoom' => array( 
  266. 'src' => self::get_asset_url( 'assets/js/zoom/jquery.zoom' . $suffix . '.js' ),  
  267. 'deps' => array( 'jquery' ),  
  268. 'version' => '1.7.15',  
  269. ),  
  270. ); 
  271. foreach ( $register_scripts as $name => $props ) { 
  272. self::register_script( $name, $props['src'], $props['deps'], $props['version'] ); 
  273.  
  274. /** 
  275. * Register all WC sty;es. 
  276. */ 
  277. private static function register_styles() { 
  278. $register_styles = array( 
  279. 'photoswipe' => array( 
  280. 'src' => self::get_asset_url( 'assets/css/photoswipe/photoswipe.css' ),  
  281. 'deps' => array(),  
  282. 'version' => WC_VERSION,  
  283. 'has_rtl' => false,  
  284. ),  
  285. 'photoswipe-default-skin' => array( 
  286. 'src' => self::get_asset_url( 'assets/css/photoswipe/default-skin/default-skin.css' ),  
  287. 'deps' => array( 'photoswipe' ),  
  288. 'version' => WC_VERSION,  
  289. 'has_rtl' => false,  
  290. ),  
  291. 'select2' => array( 
  292. 'src' => self::get_asset_url( 'assets/css/select2.css' ),  
  293. 'deps' => array(),  
  294. 'version' => WC_VERSION,  
  295. 'has_rtl' => false,  
  296. ),  
  297. 'woocommerce_prettyPhoto_css' => array( // deprecated. 
  298. 'src' => self::get_asset_url( 'assets/css/prettyPhoto.css' ),  
  299. 'deps' => array(),  
  300. 'version' => WC_VERSION,  
  301. 'has_rtl' => true,  
  302. ),  
  303. ); 
  304. foreach ( $register_styles as $name => $props ) { 
  305. self::register_style( $name, $props['src'], $props['deps'], $props['version'], 'all', $props['has_rtl'] ); 
  306.  
  307. /** 
  308. * Register/queue frontend scripts. 
  309. */ 
  310. public static function load_scripts() { 
  311. global $post; 
  312.  
  313. if ( ! did_action( 'before_woocommerce_init' ) ) { 
  314. return; 
  315.  
  316. self::register_scripts(); 
  317. self::register_styles(); 
  318.  
  319. if ( 'yes' === get_option( 'woocommerce_enable_ajax_add_to_cart' ) ) { 
  320. self::enqueue_script( 'wc-add-to-cart' ); 
  321. if ( is_cart() ) { 
  322. self::enqueue_script( 'wc-cart' ); 
  323. if ( is_checkout() || is_account_page() ) { 
  324. self::enqueue_script( 'select2' ); 
  325. self::enqueue_style( 'select2' ); 
  326.  
  327. // Password strength meter. Load in checkout, account login and edit account page. 
  328. if ( ( 'no' === get_option( 'woocommerce_registration_generate_password' ) && ! is_user_logged_in() ) || is_edit_account_page() || is_lost_password_page() ) { 
  329. self::enqueue_script( 'wc-password-strength-meter' ); 
  330. if ( is_checkout() ) { 
  331. self::enqueue_script( 'wc-checkout' ); 
  332. if ( is_add_payment_method_page() ) { 
  333. self::enqueue_script( 'wc-add-payment-method' ); 
  334. if ( is_lost_password_page() ) { 
  335. self::enqueue_script( 'wc-lost-password' ); 
  336.  
  337. // Load gallery scripts on product pages only if supported. 
  338. if ( is_product() || ( ! empty( $post->post_content ) && strstr( $post->post_content, '[product_page' ) ) ) { 
  339. if ( current_theme_supports( 'wc-product-gallery-zoom' ) ) { 
  340. self::enqueue_script( 'zoom' ); 
  341. if ( current_theme_supports( 'wc-product-gallery-slider' ) ) { 
  342. self::enqueue_script( 'flexslider' ); 
  343. if ( current_theme_supports( 'wc-product-gallery-lightbox' ) ) { 
  344. self::enqueue_script( 'photoswipe-ui-default' ); 
  345. self::enqueue_style( 'photoswipe-default-skin' ); 
  346. add_action( 'wp_footer', 'woocommerce_photoswipe' ); 
  347. self::enqueue_script( 'wc-single-product' ); 
  348.  
  349. if ( 'geolocation_ajax' === get_option( 'woocommerce_default_customer_address' ) ) { 
  350. $ua = wc_get_user_agent(); // Exclude common bots from geolocation by user agent. 
  351.  
  352. if ( ! strstr( $ua, 'bot' ) && ! strstr( $ua, 'spider' ) && ! strstr( $ua, 'crawl' ) ) { 
  353. self::enqueue_script( 'wc-geolocation' ); 
  354.  
  355. // Global frontend scripts 
  356. self::enqueue_script( 'woocommerce' ); 
  357. self::enqueue_script( 'wc-cart-fragments' ); 
  358.  
  359. // CSS Styles 
  360. if ( $enqueue_styles = self::get_styles() ) { 
  361. foreach ( $enqueue_styles as $handle => $args ) { 
  362. if ( ! isset( $args['has_rtl'] ) ) { 
  363. $args['has_rtl'] = false; 
  364.  
  365. self::enqueue_style( $handle, $args['src'], $args['deps'], $args['version'], $args['media'], $args['has_rtl'] ); 
  366.  
  367. /** 
  368. * Localize a WC script once. 
  369. * @access private 
  370. * @since 2.3.0 this needs less wp_script_is() calls due to https://core.trac.wordpress.org/ticket/28404 being added in WP 4.0. 
  371. * @param string $handle 
  372. */ 
  373. private static function localize_script( $handle ) { 
  374. if ( ! in_array( $handle, self::$wp_localize_scripts ) && wp_script_is( $handle ) && ( $data = self::get_script_data( $handle ) ) ) { 
  375. $name = str_replace( '-', '_', $handle ) . '_params'; 
  376. self::$wp_localize_scripts[] = $handle; 
  377. wp_localize_script( $handle, $name, apply_filters( $name, $data ) ); 
  378.  
  379. /** 
  380. * Return data for script handles. 
  381. * @access private 
  382. * @param string $handle 
  383. * @return array|bool 
  384. */ 
  385. private static function get_script_data( $handle ) { 
  386. global $wp; 
  387.  
  388. switch ( $handle ) { 
  389. case 'woocommerce' : 
  390. return array( 
  391. 'ajax_url' => WC()->ajax_url(),  
  392. 'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ),  
  393. ); 
  394. break; 
  395. case 'wc-geolocation' : 
  396. return array( 
  397. 'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ),  
  398. 'home_url' => home_url(),  
  399. 'is_available' => ! ( is_cart() || is_account_page() || is_checkout() || is_customize_preview() ) ? '1' : '0',  
  400. 'hash' => isset( $_GET['v'] ) ? wc_clean( $_GET['v'] ) : '',  
  401. ); 
  402. break; 
  403. case 'wc-single-product' : 
  404. return array( 
  405. 'i18n_required_rating_text' => esc_attr__( 'Please select a rating', 'woocommerce' ),  
  406. 'review_rating_required' => get_option( 'woocommerce_review_rating_required' ),  
  407. 'flexslider' => apply_filters( 'woocommerce_single_product_carousel_options', array( 
  408. 'rtl' => is_rtl(),  
  409. 'animation' => 'slide',  
  410. 'smoothHeight' => false,  
  411. 'directionNav' => false,  
  412. 'controlNav' => 'thumbnails',  
  413. 'slideshow' => false,  
  414. 'animationSpeed' => 500,  
  415. 'animationLoop' => false, // Breaks photoswipe pagination if true. 
  416. ) ),  
  417. 'zoom_enabled' => get_theme_support( 'wc-product-gallery-zoom' ),  
  418. 'photoswipe_enabled' => get_theme_support( 'wc-product-gallery-lightbox' ),  
  419. 'flexslider_enabled' => get_theme_support( 'wc-product-gallery-slider' ),  
  420. ); 
  421. break; 
  422. case 'wc-checkout' : 
  423. return array( 
  424. 'ajax_url' => WC()->ajax_url(),  
  425. 'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ),  
  426. 'update_order_review_nonce' => wp_create_nonce( 'update-order-review' ),  
  427. 'apply_coupon_nonce' => wp_create_nonce( 'apply-coupon' ),  
  428. 'remove_coupon_nonce' => wp_create_nonce( 'remove-coupon' ),  
  429. 'option_guest_checkout' => get_option( 'woocommerce_enable_guest_checkout' ),  
  430. 'checkout_url' => WC_AJAX::get_endpoint( "checkout" ),  
  431. 'is_checkout' => is_page( wc_get_page_id( 'checkout' ) ) && empty( $wp->query_vars['order-pay'] ) && ! isset( $wp->query_vars['order-received'] ) ? 1 : 0,  
  432. 'debug_mode' => defined( 'WP_DEBUG' ) && WP_DEBUG,  
  433. 'i18n_checkout_error' => esc_attr__( 'Error processing checkout. Please try again.', 'woocommerce' ),  
  434. ); 
  435. break; 
  436. case 'wc-address-i18n' : 
  437. return array( 
  438. 'locale' => json_encode( WC()->countries->get_country_locale() ),  
  439. 'locale_fields' => json_encode( WC()->countries->get_country_locale_field_selectors() ),  
  440. 'i18n_required_text' => esc_attr__( 'required', 'woocommerce' ),  
  441. ); 
  442. break; 
  443. case 'wc-cart' : 
  444. return array( 
  445. 'ajax_url' => WC()->ajax_url(),  
  446. 'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ),  
  447. 'update_shipping_method_nonce' => wp_create_nonce( "update-shipping-method" ),  
  448. 'apply_coupon_nonce' => wp_create_nonce( "apply-coupon" ),  
  449. 'remove_coupon_nonce' => wp_create_nonce( "remove-coupon" ),  
  450. ); 
  451. break; 
  452. case 'wc-cart-fragments' : 
  453. return array( 
  454. 'ajax_url' => WC()->ajax_url(),  
  455. 'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ),  
  456. 'fragment_name' => apply_filters( 'woocommerce_cart_fragment_name', 'wc_fragments' ),  
  457. ); 
  458. break; 
  459. case 'wc-add-to-cart' : 
  460. return array( 
  461. 'ajax_url' => WC()->ajax_url(),  
  462. 'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ),  
  463. 'i18n_view_cart' => esc_attr__( 'View cart', 'woocommerce' ),  
  464. 'cart_url' => apply_filters( 'woocommerce_add_to_cart_redirect', wc_get_cart_url() ),  
  465. 'is_cart' => is_cart(),  
  466. 'cart_redirect_after_add' => get_option( 'woocommerce_cart_redirect_after_add' ),  
  467. ); 
  468. break; 
  469. case 'wc-add-to-cart-variation' : 
  470. // We also need the wp.template for this script :) 
  471. wc_get_template( 'single-product/add-to-cart/variation.php' ); 
  472.  
  473. return array( 
  474. 'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ),  
  475. 'i18n_no_matching_variations_text' => esc_attr__( 'Sorry, no products matched your selection. Please choose a different combination.', 'woocommerce' ),  
  476. 'i18n_make_a_selection_text' => esc_attr__( 'Please select some product options before adding this product to your cart.', 'woocommerce' ),  
  477. 'i18n_unavailable_text' => esc_attr__( 'Sorry, this product is unavailable. Please choose a different combination.', 'woocommerce' ),  
  478. ); 
  479. break; 
  480. case 'wc-country-select' : 
  481. return array( 
  482. 'countries' => json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ),  
  483. 'i18n_select_state_text' => esc_attr__( 'Select an option…', 'woocommerce' ),  
  484. 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ),  
  485. 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ),  
  486. 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ),  
  487. 'i18n_input_too_short_n' => _x( 'Please enter %qty% or more characters', 'enhanced select', 'woocommerce' ),  
  488. 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'woocommerce' ),  
  489. 'i18n_input_too_long_n' => _x( 'Please delete %qty% characters', 'enhanced select', 'woocommerce' ),  
  490. 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'woocommerce' ),  
  491. 'i18n_selection_too_long_n' => _x( 'You can only select %qty% items', 'enhanced select', 'woocommerce' ),  
  492. 'i18n_load_more' => _x( 'Loading more results…', 'enhanced select', 'woocommerce' ),  
  493. 'i18n_searching' => _x( 'Searching…', 'enhanced select', 'woocommerce' ),  
  494. ); 
  495. break; 
  496. case 'wc-password-strength-meter' : 
  497. return array( 
  498. 'min_password_strength' => apply_filters( 'woocommerce_min_password_strength', 3 ),  
  499. 'i18n_password_error' => esc_attr__( 'Please enter a stronger password.', 'woocommerce' ),  
  500. 'i18n_password_hint' => esc_attr( wp_get_password_hint() ),  
  501. ); 
  502. break; 
  503. return false; 
  504.  
  505. /** 
  506. * Localize scripts only when enqueued. 
  507. */ 
  508. public static function localize_printed_scripts() { 
  509. foreach ( self::$scripts as $handle ) { 
  510. self::localize_script( $handle );