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3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / class-wc-frontend-scripts.php
woocommerce / includes Last commit date
abstracts 3 years ago admin 3 years ago blocks 5 years ago cli 3 years ago customizer 3 years ago data-stores 3 years ago emails 3 years ago export 3 years ago gateways 3 years ago import 4 years ago integrations 4 years ago interfaces 4 years ago legacy 3 years ago libraries 3 years ago log-handlers 4 years ago payment-tokens 5 years ago queue 4 years ago react-admin 3 years ago rest-api 3 years ago shipping 4 years ago shortcodes 3 years ago theme-support 3 years ago tracks 3 years ago traits 5 years ago walkers 5 years ago wccom-site 5 years ago widgets 4 years ago class-wc-ajax.php 3 years ago class-wc-api.php 4 years ago class-wc-auth.php 4 years ago class-wc-autoloader.php 5 years ago class-wc-background-emailer.php 5 years ago class-wc-background-updater.php 5 years ago class-wc-breadcrumb.php 5 years ago class-wc-cache-helper.php 4 years ago class-wc-cart-fees.php 5 years ago class-wc-cart-session.php 3 years ago class-wc-cart-totals.php 4 years ago class-wc-cart.php 3 years ago class-wc-checkout.php 4 years ago class-wc-cli.php 3 years ago class-wc-comments.php 3 years ago class-wc-countries.php 3 years ago class-wc-coupon.php 4 years ago class-wc-customer-download-log.php 5 years ago class-wc-customer-download.php 4 years ago class-wc-customer.php 4 years ago class-wc-data-exception.php 8 years ago class-wc-data-store.php 3 years ago class-wc-datetime.php 4 years ago class-wc-deprecated-action-hooks.php 8 years ago class-wc-deprecated-filter-hooks.php 4 years ago class-wc-discounts.php 3 years ago class-wc-download-handler.php 3 years ago class-wc-emails.php 3 years ago class-wc-embed.php 5 years ago class-wc-form-handler.php 4 years ago class-wc-frontend-scripts.php 3 years ago class-wc-geo-ip.php 4 years ago class-wc-geolite-integration.php 6 years ago class-wc-geolocation.php 3 years ago class-wc-https.php 4 years ago class-wc-install.php 3 years ago class-wc-integrations.php 5 years ago class-wc-log-levels.php 5 years ago class-wc-logger.php 4 years ago class-wc-meta-data.php 4 years ago class-wc-order-factory.php 3 years ago class-wc-order-item-coupon.php 4 years ago class-wc-order-item-fee.php 4 years ago class-wc-order-item-meta.php 4 years ago class-wc-order-item-product.php 4 years ago class-wc-order-item-shipping.php 4 years ago class-wc-order-item-tax.php 4 years ago class-wc-order-item.php 4 years ago class-wc-order-query.php 4 years ago class-wc-order-refund.php 3 years ago class-wc-order.php 3 years ago class-wc-payment-gateways.php 4 years ago class-wc-payment-tokens.php 5 years ago class-wc-post-data.php 3 years ago class-wc-post-types.php 3 years ago class-wc-privacy-background-process.php 5 years ago class-wc-privacy-erasers.php 4 years ago class-wc-privacy-exporters.php 4 years ago class-wc-privacy.php 4 years ago class-wc-product-attribute.php 4 years ago class-wc-product-download.php 4 years ago class-wc-product-external.php 5 years ago class-wc-product-factory.php 5 years ago class-wc-product-grouped.php 8 years ago class-wc-product-query.php 5 years ago class-wc-product-simple.php 3 years ago class-wc-product-variable.php 4 years ago class-wc-product-variation.php 4 years ago class-wc-query.php 3 years ago class-wc-rate-limiter.php 4 years ago class-wc-regenerate-images-request.php 3 years ago class-wc-regenerate-images.php 3 years ago class-wc-register-wp-admin-settings.php 4 years ago class-wc-rest-authentication.php 5 years ago class-wc-rest-exception.php 5 years ago class-wc-session-handler.php 4 years ago class-wc-shipping-rate.php 4 years ago class-wc-shipping-zone.php 5 years ago class-wc-shipping-zones.php 5 years ago class-wc-shipping.php 4 years ago class-wc-shortcodes.php 5 years ago class-wc-structured-data.php 5 years ago class-wc-tax.php 4 years ago class-wc-template-loader.php 4 years ago class-wc-tracker.php 3 years ago class-wc-validation.php 5 years ago class-wc-webhook.php 3 years ago class-woocommerce.php 3 years ago wc-account-functions.php 5 years ago wc-attribute-functions.php 3 years ago wc-cart-functions.php 3 years ago wc-conditional-functions.php 3 years ago wc-core-functions.php 3 years ago wc-coupon-functions.php 5 years ago wc-deprecated-functions.php 4 years ago wc-formatting-functions.php 3 years ago wc-notice-functions.php 5 years ago wc-order-functions.php 3 years ago wc-order-item-functions.php 5 years ago wc-page-functions.php 5 years ago wc-product-functions.php 3 years ago wc-rest-functions.php 3 years ago wc-stock-functions.php 4 years ago wc-template-functions.php 3 years ago wc-template-hooks.php 5 years ago wc-term-functions.php 3 years ago wc-update-functions.php 3 years ago wc-user-functions.php 3 years ago wc-webhook-functions.php 4 years ago wc-widget-functions.php 5 years ago
class-wc-frontend-scripts.php
639 lines
1 <?php
2 /**
3 * Handle frontend scripts
4 *
5 * @package WooCommerce\Classes
6 * @version 2.3.0
7 */
8
9 // phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment
10
11 use Automattic\Jetpack\Constants;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Frontend scripts class.
19 */
20 class WC_Frontend_Scripts {
21
22 /**
23 * Contains an array of script handles registered by WC.
24 *
25 * @var array
26 */
27 private static $scripts = array();
28
29 /**
30 * Contains an array of script handles registered by WC.
31 *
32 * @var array
33 */
34 private static $styles = array();
35
36 /**
37 * Contains an array of script handles localized by WC.
38 *
39 * @var array
40 */
41 private static $wp_localize_scripts = array();
42
43 /**
44 * Hook in methods.
45 */
46 public static function init() {
47 add_action( 'wp_enqueue_scripts', array( __CLASS__, 'load_scripts' ) );
48 add_action( 'wp_print_scripts', array( __CLASS__, 'localize_printed_scripts' ), 5 );
49 add_action( 'wp_print_footer_scripts', array( __CLASS__, 'localize_printed_scripts' ), 5 );
50 }
51
52 /**
53 * Get styles for the frontend.
54 *
55 * @return array
56 */
57 public static function get_styles() {
58 $version = Constants::get_constant( 'WC_VERSION' );
59
60 /**
61 * Filter list of WooCommerce styles to enqueue.
62 *
63 * @since 2.1.0
64 * @param array List of default WooCommerce styles.
65 * @retrun array List of styles to enqueue.
66 */
67 $styles = apply_filters(
68 'woocommerce_enqueue_styles',
69 array(
70 'woocommerce-layout' => array(
71 'src' => self::get_asset_url( 'assets/css/woocommerce-layout.css' ),
72 'deps' => '',
73 'version' => $version,
74 'media' => 'all',
75 'has_rtl' => true,
76 ),
77 'woocommerce-smallscreen' => array(
78 'src' => self::get_asset_url( 'assets/css/woocommerce-smallscreen.css' ),
79 'deps' => 'woocommerce-layout',
80 'version' => $version,
81 'media' => 'only screen and (max-width: ' . apply_filters( 'woocommerce_style_smallscreen_breakpoint', '768px' ) . ')',
82 'has_rtl' => true,
83 ),
84 'woocommerce-general' => array(
85 'src' => self::get_asset_url( 'assets/css/woocommerce.css' ),
86 'deps' => '',
87 'version' => $version,
88 'media' => 'all',
89 'has_rtl' => true,
90 ),
91 'woocommerce-blocktheme' => wc_current_theme_is_fse_theme() ? array(
92 'src' => self::get_asset_url( 'assets/css/woocommerce-blocktheme.css' ),
93 'deps' => '',
94 'version' => $version,
95 'media' => 'all',
96 'has_rtl' => true,
97 ) : false,
98 )
99 );
100 return is_array( $styles ) ? array_filter( $styles ) : array();
101 }
102
103 /**
104 * Return asset URL.
105 *
106 * @param string $path Assets path.
107 * @return string
108 */
109 private static function get_asset_url( $path ) {
110 return apply_filters( 'woocommerce_get_asset_url', plugins_url( $path, WC_PLUGIN_FILE ), $path );
111 }
112
113 /**
114 * Register a script for use.
115 *
116 * @uses wp_register_script()
117 * @param string $handle Name of the script. Should be unique.
118 * @param string $path Full URL of the script, or path of the script relative to the WordPress root directory.
119 * @param string[] $deps An array of registered script handles this script depends on.
120 * @param string $version String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
121 * @param boolean $in_footer Whether to enqueue the script before </body> instead of in the <head>. Default 'false'.
122 */
123 private static function register_script( $handle, $path, $deps = array( 'jquery' ), $version = WC_VERSION, $in_footer = true ) {
124 self::$scripts[] = $handle;
125 wp_register_script( $handle, $path, $deps, $version, $in_footer );
126 }
127
128 /**
129 * Register and enqueue a script for use.
130 *
131 * @uses wp_enqueue_script()
132 * @param string $handle Name of the script. Should be unique.
133 * @param string $path Full URL of the script, or path of the script relative to the WordPress root directory.
134 * @param string[] $deps An array of registered script handles this script depends on.
135 * @param string $version String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
136 * @param boolean $in_footer Whether to enqueue the script before </body> instead of in the <head>. Default 'false'.
137 */
138 private static function enqueue_script( $handle, $path = '', $deps = array( 'jquery' ), $version = WC_VERSION, $in_footer = true ) {
139 if ( ! in_array( $handle, self::$scripts, true ) && $path ) {
140 self::register_script( $handle, $path, $deps, $version, $in_footer );
141 }
142 wp_enqueue_script( $handle );
143 }
144
145 /**
146 * Register a style for use.
147 *
148 * @uses wp_register_style()
149 * @param string $handle Name of the stylesheet. Should be unique.
150 * @param string $path Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
151 * @param string[] $deps An array of registered stylesheet handles this stylesheet depends on.
152 * @param string $version String specifying stylesheet version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
153 * @param string $media The media for which this stylesheet has been defined. Accepts media types like 'all', 'print' and 'screen', or media queries like '(orientation: portrait)' and '(max-width: 640px)'.
154 * @param boolean $has_rtl If has RTL version to load too.
155 */
156 private static function register_style( $handle, $path, $deps = array(), $version = WC_VERSION, $media = 'all', $has_rtl = false ) {
157 self::$styles[] = $handle;
158 wp_register_style( $handle, $path, $deps, $version, $media );
159
160 if ( $has_rtl ) {
161 wp_style_add_data( $handle, 'rtl', 'replace' );
162 }
163 }
164
165 /**
166 * Register and enqueue a styles for use.
167 *
168 * @uses wp_enqueue_style()
169 * @param string $handle Name of the stylesheet. Should be unique.
170 * @param string $path Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
171 * @param string[] $deps An array of registered stylesheet handles this stylesheet depends on.
172 * @param string $version String specifying stylesheet version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
173 * @param string $media The media for which this stylesheet has been defined. Accepts media types like 'all', 'print' and 'screen', or media queries like '(orientation: portrait)' and '(max-width: 640px)'.
174 * @param boolean $has_rtl If has RTL version to load too.
175 */
176 private static function enqueue_style( $handle, $path = '', $deps = array(), $version = WC_VERSION, $media = 'all', $has_rtl = false ) {
177 if ( ! in_array( $handle, self::$styles, true ) && $path ) {
178 self::register_style( $handle, $path, $deps, $version, $media, $has_rtl );
179 }
180 wp_enqueue_style( $handle );
181 }
182
183 /**
184 * Register all WC scripts.
185 */
186 private static function register_scripts() {
187 $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min';
188 $version = Constants::get_constant( 'WC_VERSION' );
189
190 $register_scripts = array(
191 'flexslider' => array(
192 'src' => self::get_asset_url( 'assets/js/flexslider/jquery.flexslider' . $suffix . '.js' ),
193 'deps' => array( 'jquery' ),
194 'version' => '2.7.2-wc.' . $version,
195 ),
196 'js-cookie' => array(
197 'src' => self::get_asset_url( 'assets/js/js-cookie/js.cookie' . $suffix . '.js' ),
198 'deps' => array(),
199 'version' => '2.1.4-wc.' . $version,
200 ),
201 'jquery-blockui' => array(
202 'src' => self::get_asset_url( 'assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js' ),
203 'deps' => array( 'jquery' ),
204 'version' => '2.7.0-wc.' . $version,
205 ),
206 'jquery-cookie' => array( // deprecated.
207 'src' => self::get_asset_url( 'assets/js/jquery-cookie/jquery.cookie' . $suffix . '.js' ),
208 'deps' => array( 'jquery' ),
209 'version' => '1.4.1-wc.' . $version,
210 ),
211 'jquery-payment' => array(
212 'src' => self::get_asset_url( 'assets/js/jquery-payment/jquery.payment' . $suffix . '.js' ),
213 'deps' => array( 'jquery' ),
214 'version' => '3.0.0-wc.' . $version,
215 ),
216 'photoswipe' => array(
217 'src' => self::get_asset_url( 'assets/js/photoswipe/photoswipe' . $suffix . '.js' ),
218 'deps' => array(),
219 'version' => '4.1.1-wc.' . $version,
220 ),
221 'photoswipe-ui-default' => array(
222 'src' => self::get_asset_url( 'assets/js/photoswipe/photoswipe-ui-default' . $suffix . '.js' ),
223 'deps' => array( 'photoswipe' ),
224 'version' => '4.1.1-wc.' . $version,
225 ),
226 'prettyPhoto' => array( // deprecated.
227 'src' => self::get_asset_url( 'assets/js/prettyPhoto/jquery.prettyPhoto' . $suffix . '.js' ),
228 'deps' => array( 'jquery' ),
229 'version' => '3.1.6-wc.' . $version,
230 ),
231 'prettyPhoto-init' => array( // deprecated.
232 'src' => self::get_asset_url( 'assets/js/prettyPhoto/jquery.prettyPhoto.init' . $suffix . '.js' ),
233 'deps' => array( 'jquery', 'prettyPhoto' ),
234 'version' => $version,
235 ),
236 'select2' => array(
237 'src' => self::get_asset_url( 'assets/js/select2/select2.full' . $suffix . '.js' ),
238 'deps' => array( 'jquery' ),
239 'version' => '4.0.3-wc.' . $version,
240 ),
241 'selectWoo' => array(
242 'src' => self::get_asset_url( 'assets/js/selectWoo/selectWoo.full' . $suffix . '.js' ),
243 'deps' => array( 'jquery' ),
244 'version' => '1.0.9-wc.' . $version,
245 ),
246 'wc-address-i18n' => array(
247 'src' => self::get_asset_url( 'assets/js/frontend/address-i18n' . $suffix . '.js' ),
248 'deps' => array( 'jquery', 'wc-country-select' ),
249 'version' => $version,
250 ),
251 'wc-add-payment-method' => array(
252 'src' => self::get_asset_url( 'assets/js/frontend/add-payment-method' . $suffix . '.js' ),
253 'deps' => array( 'jquery', 'woocommerce' ),
254 'version' => $version,
255 ),
256 'wc-cart' => array(
257 'src' => self::get_asset_url( 'assets/js/frontend/cart' . $suffix . '.js' ),
258 'deps' => array( 'jquery', 'woocommerce', 'wc-country-select', 'wc-address-i18n' ),
259 'version' => $version,
260 ),
261 'wc-cart-fragments' => array(
262 'src' => self::get_asset_url( 'assets/js/frontend/cart-fragments' . $suffix . '.js' ),
263 'deps' => array( 'jquery', 'js-cookie' ),
264 'version' => $version,
265 ),
266 'wc-checkout' => array(
267 'src' => self::get_asset_url( 'assets/js/frontend/checkout' . $suffix . '.js' ),
268 'deps' => array( 'jquery', 'woocommerce', 'wc-country-select', 'wc-address-i18n' ),
269 'version' => $version,
270 ),
271 'wc-country-select' => array(
272 'src' => self::get_asset_url( 'assets/js/frontend/country-select' . $suffix . '.js' ),
273 'deps' => array( 'jquery' ),
274 'version' => $version,
275 ),
276 'wc-credit-card-form' => array(
277 'src' => self::get_asset_url( 'assets/js/frontend/credit-card-form' . $suffix . '.js' ),
278 'deps' => array( 'jquery', 'jquery-payment' ),
279 'version' => $version,
280 ),
281 'wc-add-to-cart' => array(
282 'src' => self::get_asset_url( 'assets/js/frontend/add-to-cart' . $suffix . '.js' ),
283 'deps' => array( 'jquery', 'jquery-blockui' ),
284 'version' => $version,
285 ),
286 'wc-add-to-cart-variation' => array(
287 'src' => self::get_asset_url( 'assets/js/frontend/add-to-cart-variation' . $suffix . '.js' ),
288 'deps' => array( 'jquery', 'wp-util', 'jquery-blockui' ),
289 'version' => $version,
290 ),
291 'wc-geolocation' => array(
292 'src' => self::get_asset_url( 'assets/js/frontend/geolocation' . $suffix . '.js' ),
293 'deps' => array( 'jquery' ),
294 'version' => $version,
295 ),
296 'wc-lost-password' => array(
297 'src' => self::get_asset_url( 'assets/js/frontend/lost-password' . $suffix . '.js' ),
298 'deps' => array( 'jquery', 'woocommerce' ),
299 'version' => $version,
300 ),
301 'wc-password-strength-meter' => array(
302 'src' => self::get_asset_url( 'assets/js/frontend/password-strength-meter' . $suffix . '.js' ),
303 'deps' => array( 'jquery', 'password-strength-meter' ),
304 'version' => $version,
305 ),
306 'wc-single-product' => array(
307 'src' => self::get_asset_url( 'assets/js/frontend/single-product' . $suffix . '.js' ),
308 'deps' => array( 'jquery' ),
309 'version' => $version,
310 ),
311 'woocommerce' => array(
312 'src' => self::get_asset_url( 'assets/js/frontend/woocommerce' . $suffix . '.js' ),
313 'deps' => array( 'jquery', 'jquery-blockui', 'js-cookie' ),
314 'version' => $version,
315 ),
316 'zoom' => array(
317 'src' => self::get_asset_url( 'assets/js/zoom/jquery.zoom' . $suffix . '.js' ),
318 'deps' => array( 'jquery' ),
319 'version' => '1.7.21-wc.' . $version,
320 ),
321 );
322 foreach ( $register_scripts as $name => $props ) {
323 self::register_script( $name, $props['src'], $props['deps'], $props['version'] );
324 }
325 }
326
327 /**
328 * Register all WC styles.
329 */
330 private static function register_styles() {
331 $version = Constants::get_constant( 'WC_VERSION' );
332
333 $register_styles = array(
334 'photoswipe' => array(
335 'src' => self::get_asset_url( 'assets/css/photoswipe/photoswipe.min.css' ),
336 'deps' => array(),
337 'version' => $version,
338 'has_rtl' => false,
339 ),
340 'photoswipe-default-skin' => array(
341 'src' => self::get_asset_url( 'assets/css/photoswipe/default-skin/default-skin.min.css' ),
342 'deps' => array( 'photoswipe' ),
343 'version' => $version,
344 'has_rtl' => false,
345 ),
346 'select2' => array(
347 'src' => self::get_asset_url( 'assets/css/select2.css' ),
348 'deps' => array(),
349 'version' => $version,
350 'has_rtl' => false,
351 ),
352 'woocommerce_prettyPhoto_css' => array( // deprecated.
353 'src' => self::get_asset_url( 'assets/css/prettyPhoto.css' ),
354 'deps' => array(),
355 'version' => $version,
356 'has_rtl' => true,
357 ),
358 );
359 foreach ( $register_styles as $name => $props ) {
360 self::register_style( $name, $props['src'], $props['deps'], $props['version'], 'all', $props['has_rtl'] );
361 }
362 }
363
364 /**
365 * Register/queue frontend scripts.
366 */
367 public static function load_scripts() {
368 global $post;
369
370 if ( ! did_action( 'before_woocommerce_init' ) ) {
371 return;
372 }
373
374 self::register_scripts();
375 self::register_styles();
376
377 if ( 'yes' === get_option( 'woocommerce_enable_ajax_add_to_cart' ) ) {
378 self::enqueue_script( 'wc-add-to-cart' );
379 }
380 if ( is_cart() ) {
381 self::enqueue_script( 'wc-cart' );
382 }
383 if ( is_cart() || is_checkout() || is_account_page() ) {
384 self::enqueue_script( 'selectWoo' );
385 self::enqueue_style( 'select2' );
386
387 // Password strength meter. Load in checkout, account login and edit account page.
388 if ( ( 'no' === get_option( 'woocommerce_registration_generate_password' ) && ! is_user_logged_in() ) || is_edit_account_page() || is_lost_password_page() ) {
389 self::enqueue_script( 'wc-password-strength-meter' );
390 }
391 }
392 if ( is_checkout() ) {
393 self::enqueue_script( 'wc-checkout' );
394 }
395 if ( is_add_payment_method_page() ) {
396 self::enqueue_script( 'wc-add-payment-method' );
397 }
398 if ( is_lost_password_page() ) {
399 self::enqueue_script( 'wc-lost-password' );
400 }
401
402 // Load gallery scripts on product pages only if supported.
403 if ( is_product() || ( ! empty( $post->post_content ) && strstr( $post->post_content, '[product_page' ) ) ) {
404 if ( current_theme_supports( 'wc-product-gallery-zoom' ) ) {
405 self::enqueue_script( 'zoom' );
406 }
407 if ( current_theme_supports( 'wc-product-gallery-slider' ) ) {
408 self::enqueue_script( 'flexslider' );
409 }
410 if ( current_theme_supports( 'wc-product-gallery-lightbox' ) ) {
411 self::enqueue_script( 'photoswipe-ui-default' );
412 self::enqueue_style( 'photoswipe-default-skin' );
413 add_action( 'wp_footer', 'woocommerce_photoswipe' );
414 }
415 self::enqueue_script( 'wc-single-product' );
416 }
417
418 // Only enqueue the geolocation script if the Default Current Address is set to "Geolocate
419 // (with Page Caching Support) and outside of the cart, checkout, account and customizer preview.
420 if (
421 'geolocation_ajax' === get_option( 'woocommerce_default_customer_address' )
422 && ! ( is_cart() || is_account_page() || is_checkout() || is_customize_preview() )
423 ) {
424 $ua = strtolower( wc_get_user_agent() ); // Exclude common bots from geolocation by user agent.
425
426 if ( ! strstr( $ua, 'bot' ) && ! strstr( $ua, 'spider' ) && ! strstr( $ua, 'crawl' ) ) {
427 self::enqueue_script( 'wc-geolocation' );
428 }
429 }
430
431 // Global frontend scripts.
432 self::enqueue_script( 'woocommerce' );
433 self::enqueue_script( 'wc-cart-fragments' );
434
435 // CSS Styles.
436 $enqueue_styles = self::get_styles();
437 if ( $enqueue_styles ) {
438 foreach ( $enqueue_styles as $handle => $args ) {
439 if ( ! isset( $args['has_rtl'] ) ) {
440 $args['has_rtl'] = false;
441 }
442
443 self::enqueue_style( $handle, $args['src'], $args['deps'], $args['version'], $args['media'], $args['has_rtl'] );
444 }
445 }
446
447 // Placeholder style.
448 wp_register_style( 'woocommerce-inline', false ); // phpcs:ignore
449 wp_enqueue_style( 'woocommerce-inline' );
450
451 if ( true === wc_string_to_bool( get_option( 'woocommerce_checkout_highlight_required_fields', 'yes' ) ) ) {
452 wp_add_inline_style( 'woocommerce-inline', '.woocommerce form .form-row .required { visibility: visible; }' );
453 } else {
454 wp_add_inline_style( 'woocommerce-inline', '.woocommerce form .form-row .required { visibility: hidden; }' );
455 }
456 }
457
458 /**
459 * Localize a WC script once.
460 *
461 * @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.
462 * @param string $handle Script handle the data will be attached to.
463 */
464 private static function localize_script( $handle ) {
465 if ( ! in_array( $handle, self::$wp_localize_scripts, true ) && wp_script_is( $handle ) ) {
466 $data = self::get_script_data( $handle );
467
468 if ( ! $data ) {
469 return;
470 }
471
472 $name = str_replace( '-', '_', $handle ) . '_params';
473 self::$wp_localize_scripts[] = $handle;
474 wp_localize_script( $handle, $name, apply_filters( $name, $data ) );
475 }
476 }
477
478 /**
479 * Return data for script handles.
480 *
481 * @param string $handle Script handle the data will be attached to.
482 * @return array|bool
483 */
484 private static function get_script_data( $handle ) {
485 global $wp;
486
487 switch ( $handle ) {
488 case 'woocommerce':
489 $params = array(
490 'ajax_url' => WC()->ajax_url(),
491 'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
492 );
493 break;
494 case 'wc-geolocation':
495 $params = array(
496 'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
497 'home_url' => remove_query_arg( 'lang', home_url() ), // FIX for WPML compatibility.
498 );
499 break;
500 case 'wc-single-product':
501 $params = array(
502 'i18n_required_rating_text' => esc_attr__( 'Please select a rating', 'woocommerce' ),
503 'review_rating_required' => wc_review_ratings_required() ? 'yes' : 'no',
504 'flexslider' => apply_filters(
505 'woocommerce_single_product_carousel_options',
506 array(
507 'rtl' => is_rtl(),
508 'animation' => 'slide',
509 'smoothHeight' => true,
510 'directionNav' => false,
511 'controlNav' => 'thumbnails',
512 'slideshow' => false,
513 'animationSpeed' => 500,
514 'animationLoop' => false, // Breaks photoswipe pagination if true.
515 'allowOneSlide' => false,
516 )
517 ),
518 'zoom_enabled' => apply_filters( 'woocommerce_single_product_zoom_enabled', get_theme_support( 'wc-product-gallery-zoom' ) ),
519 'zoom_options' => apply_filters( 'woocommerce_single_product_zoom_options', array() ),
520 'photoswipe_enabled' => apply_filters( 'woocommerce_single_product_photoswipe_enabled', get_theme_support( 'wc-product-gallery-lightbox' ) ),
521 'photoswipe_options' => apply_filters(
522 'woocommerce_single_product_photoswipe_options',
523 array(
524 'shareEl' => false,
525 'closeOnScroll' => false,
526 'history' => false,
527 'hideAnimationDuration' => 0,
528 'showAnimationDuration' => 0,
529 )
530 ),
531 'flexslider_enabled' => apply_filters( 'woocommerce_single_product_flexslider_enabled', get_theme_support( 'wc-product-gallery-slider' ) ),
532 );
533 break;
534 case 'wc-checkout':
535 $params = array(
536 'ajax_url' => WC()->ajax_url(),
537 'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
538 'update_order_review_nonce' => wp_create_nonce( 'update-order-review' ),
539 'apply_coupon_nonce' => wp_create_nonce( 'apply-coupon' ),
540 'remove_coupon_nonce' => wp_create_nonce( 'remove-coupon' ),
541 'option_guest_checkout' => get_option( 'woocommerce_enable_guest_checkout' ),
542 'checkout_url' => WC_AJAX::get_endpoint( 'checkout' ),
543 'is_checkout' => is_checkout() && empty( $wp->query_vars['order-pay'] ) && ! isset( $wp->query_vars['order-received'] ) ? 1 : 0,
544 'debug_mode' => Constants::is_true( 'WP_DEBUG' ),
545 'i18n_checkout_error' => esc_attr__( 'Error processing checkout. Please try again.', 'woocommerce' ),
546 );
547 break;
548 case 'wc-address-i18n':
549 $params = array(
550 'locale' => wp_json_encode( WC()->countries->get_country_locale() ),
551 'locale_fields' => wp_json_encode( WC()->countries->get_country_locale_field_selectors() ),
552 'i18n_required_text' => esc_attr__( 'required', 'woocommerce' ),
553 'i18n_optional_text' => esc_html__( 'optional', 'woocommerce' ),
554 );
555 break;
556 case 'wc-cart':
557 $params = array(
558 'ajax_url' => WC()->ajax_url(),
559 'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
560 'update_shipping_method_nonce' => wp_create_nonce( 'update-shipping-method' ),
561 'apply_coupon_nonce' => wp_create_nonce( 'apply-coupon' ),
562 'remove_coupon_nonce' => wp_create_nonce( 'remove-coupon' ),
563 );
564 break;
565 case 'wc-cart-fragments':
566 $params = array(
567 'ajax_url' => WC()->ajax_url(),
568 'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
569 'cart_hash_key' => apply_filters( 'woocommerce_cart_hash_key', 'wc_cart_hash_' . md5( get_current_blog_id() . '_' . get_site_url( get_current_blog_id(), '/' ) . get_template() ) ),
570 'fragment_name' => apply_filters( 'woocommerce_cart_fragment_name', 'wc_fragments_' . md5( get_current_blog_id() . '_' . get_site_url( get_current_blog_id(), '/' ) . get_template() ) ),
571 'request_timeout' => 5000,
572 );
573 break;
574 case 'wc-add-to-cart':
575 $params = array(
576 'ajax_url' => WC()->ajax_url(),
577 'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
578 'i18n_view_cart' => esc_attr__( 'View cart', 'woocommerce' ),
579 'cart_url' => apply_filters( 'woocommerce_add_to_cart_redirect', wc_get_cart_url(), null ),
580 'is_cart' => is_cart(),
581 'cart_redirect_after_add' => get_option( 'woocommerce_cart_redirect_after_add' ),
582 );
583 break;
584 case 'wc-add-to-cart-variation':
585 // We also need the wp.template for this script :).
586 wc_get_template( 'single-product/add-to-cart/variation.php' );
587
588 $params = array(
589 'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
590 'i18n_no_matching_variations_text' => esc_attr__( 'Sorry, no products matched your selection. Please choose a different combination.', 'woocommerce' ),
591 'i18n_make_a_selection_text' => esc_attr__( 'Please select some product options before adding this product to your cart.', 'woocommerce' ),
592 'i18n_unavailable_text' => esc_attr__( 'Sorry, this product is unavailable. Please choose a different combination.', 'woocommerce' ),
593 );
594 break;
595 case 'wc-country-select':
596 $params = array(
597 'countries' => wp_json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ),
598 'i18n_select_state_text' => esc_attr__( 'Select an option&hellip;', 'woocommerce' ),
599 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ),
600 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ),
601 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ),
602 'i18n_input_too_short_n' => _x( 'Please enter %qty% or more characters', 'enhanced select', 'woocommerce' ),
603 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'woocommerce' ),
604 'i18n_input_too_long_n' => _x( 'Please delete %qty% characters', 'enhanced select', 'woocommerce' ),
605 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'woocommerce' ),
606 'i18n_selection_too_long_n' => _x( 'You can only select %qty% items', 'enhanced select', 'woocommerce' ),
607 'i18n_load_more' => _x( 'Loading more results&hellip;', 'enhanced select', 'woocommerce' ),
608 'i18n_searching' => _x( 'Searching&hellip;', 'enhanced select', 'woocommerce' ),
609 );
610 break;
611 case 'wc-password-strength-meter':
612 $params = array(
613 'min_password_strength' => apply_filters( 'woocommerce_min_password_strength', 3 ),
614 'stop_checkout' => apply_filters( 'woocommerce_enforce_password_strength_meter_on_checkout', false ),
615 'i18n_password_error' => esc_attr__( 'Please enter a stronger password.', 'woocommerce' ),
616 'i18n_password_hint' => esc_attr( wp_get_password_hint() ),
617 );
618 break;
619 default:
620 $params = false;
621 }
622
623 $params = apply_filters_deprecated( $handle . '_params', array( $params ), '3.0.0', 'woocommerce_get_script_data' );
624
625 return apply_filters( 'woocommerce_get_script_data', $params, $handle );
626 }
627
628 /**
629 * Localize scripts only when enqueued.
630 */
631 public static function localize_printed_scripts() {
632 foreach ( self::$scripts as $handle ) {
633 self::localize_script( $handle );
634 }
635 }
636 }
637
638 WC_Frontend_Scripts::init();
639