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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 4 months ago admin 4 months ago blocks 10 months ago cli 8 months ago customizer 6 months ago data-stores 4 months ago emails 4 months ago export 1 year ago gateways 4 months ago import 11 months ago integrations 2 years ago interfaces 1 year ago legacy 1 year ago libraries 1 year ago log-handlers 1 year ago payment-tokens 5 years ago product-usage 1 year ago queue 4 years ago react-admin 4 months ago rest-api 4 months ago shipping 6 months ago shortcodes 4 months ago theme-support 2 years ago tracks 4 months ago traits 5 years ago walkers 5 years ago wccom-site 9 months ago widgets 6 months ago class-wc-ajax.php 4 months ago class-wc-auth.php 1 year ago class-wc-autoloader.php 8 months ago class-wc-background-emailer.php 5 years ago class-wc-background-updater.php 5 years ago class-wc-brands-brand-settings-manager.php 1 year ago class-wc-brands-coupons.php 1 year ago class-wc-brands.php 4 months ago class-wc-breadcrumb.php 4 months ago class-wc-cache-helper.php 8 months ago class-wc-cart-fees.php 2 years ago class-wc-cart-session.php 4 months ago class-wc-cart-totals.php 10 months ago class-wc-cart.php 4 months ago class-wc-checkout.php 1 year ago class-wc-cli.php 9 months ago class-wc-comments.php 4 months ago class-wc-countries.php 4 months ago class-wc-coupon.php 6 months ago class-wc-customer-download-log.php 5 years ago class-wc-customer-download.php 1 year ago class-wc-customer.php 9 months 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 2 years ago class-wc-deprecated-filter-hooks.php 3 years ago class-wc-discounts.php 10 months ago class-wc-download-handler.php 1 year ago class-wc-emails.php 4 months ago class-wc-embed.php 1 year ago class-wc-form-handler.php 4 months ago class-wc-frontend-scripts.php 4 months ago class-wc-geo-ip.php 8 months ago class-wc-geolite-integration.php 6 years ago class-wc-geolocation.php 1 year ago class-wc-https.php 2 years ago class-wc-install.php 4 months ago class-wc-integrations.php 5 years ago class-wc-log-levels.php 2 years ago class-wc-logger.php 1 year ago class-wc-meta-data.php 4 years ago class-wc-order-factory.php 4 months ago class-wc-order-item-coupon.php 4 years ago class-wc-order-item-fee.php 4 months ago class-wc-order-item-meta.php 4 years ago class-wc-order-item-product.php 4 months ago class-wc-order-item-shipping.php 4 months ago class-wc-order-item-tax.php 4 years ago class-wc-order-item.php 4 months ago class-wc-order-query.php 4 years ago class-wc-order-refund.php 1 year ago class-wc-order.php 6 months ago class-wc-payment-gateways.php 4 months ago class-wc-payment-tokens.php 3 years ago class-wc-post-data.php 6 months ago class-wc-post-types.php 4 months ago class-wc-privacy-background-process.php 1 year ago class-wc-privacy-erasers.php 9 months ago class-wc-privacy-exporters.php 4 years ago class-wc-privacy.php 11 months ago class-wc-product-attribute.php 4 years ago class-wc-product-download.php 2 years ago class-wc-product-external.php 1 year ago class-wc-product-factory.php 4 months ago class-wc-product-grouped.php 10 months ago class-wc-product-query.php 1 year ago class-wc-product-simple.php 10 months ago class-wc-product-variable.php 4 months ago class-wc-product-variation.php 1 year ago class-wc-query.php 4 months ago class-wc-rate-limiter.php 4 years ago class-wc-regenerate-images-request.php 3 years ago class-wc-regenerate-images.php 1 year ago class-wc-register-wp-admin-settings.php 4 years ago class-wc-rest-authentication.php 1 year ago class-wc-rest-exception.php 5 years ago class-wc-session-handler.php 8 months ago class-wc-shipping-rate.php 11 months ago class-wc-shipping-zone.php 5 years ago class-wc-shipping-zones.php 6 months ago class-wc-shipping.php 1 year ago class-wc-shortcodes.php 1 year ago class-wc-structured-data.php 6 months ago class-wc-tax.php 4 months ago class-wc-template-loader.php 6 months ago class-wc-tracker.php 8 months ago class-wc-validation.php 2 years ago class-wc-webhook.php 8 months ago class-woocommerce.php 4 months ago wc-account-functions.php 6 months ago wc-attribute-functions.php 9 months ago wc-brands-functions.php 1 year ago wc-cart-functions.php 4 months ago wc-conditional-functions.php 10 months ago wc-core-functions.php 4 months ago wc-coupon-functions.php 4 months ago wc-deprecated-functions.php 9 months ago wc-formatting-functions.php 6 months ago wc-notice-functions.php 4 months ago wc-order-functions.php 4 months ago wc-order-item-functions.php 3 years ago wc-order-step-logger-functions.php 6 months ago wc-page-functions.php 1 year ago wc-product-functions.php 4 months ago wc-rest-functions.php 6 months ago wc-stock-functions.php 6 months ago wc-template-functions.php 4 months ago wc-template-hooks.php 9 months ago wc-term-functions.php 6 months ago wc-update-functions.php 4 months ago wc-user-functions.php 6 months ago wc-webhook-functions.php 1 year ago wc-widget-functions.php 5 years ago
class-wc-frontend-scripts.php
791 lines
1 <?php
2 /**
3 * Handle frontend scripts
4 *
5 * @package WooCommerce\Classes
6 * @version 3.9.0
7 * @since 2.3.0
8 */
9
10 // phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment
11
12 use Automattic\Jetpack\Constants;
13 use Automattic\WooCommerce\Admin\Features\Features;
14 use Automattic\WooCommerce\Internal\AddressProvider\AddressProviderController;
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit;
18 }
19
20 /**
21 * Frontend scripts class.
22 *
23 * These scripts are enqueued in the frontend of the store. The registered script handles in this class
24 * can be used to enqueue the scripts in the frontend by third party plugins and the handles will follow
25 * WooCommerce's L-1 support policy. Scripts registered outside of this class do not guarantee support
26 * and can be removed in future versions of WooCommerce.
27 */
28 class WC_Frontend_Scripts {
29
30 /**
31 * Contains an array of script handles registered by WC.
32 *
33 * @var array
34 */
35 private static $registered_scripts = array();
36
37 /**
38 * Contains an array of script handles registered by WC.
39 *
40 * @var array
41 */
42 private static $styles = array();
43
44 /**
45 * Contains an array of script handles localized by WC.
46 *
47 * @var array
48 */
49 private static $wp_localize_scripts = array();
50
51 /**
52 * Hook in methods.
53 */
54 public static function init() {
55 add_action( 'wp_enqueue_scripts', array( __CLASS__, 'load_scripts' ) );
56 add_action( 'wp_print_scripts', array( __CLASS__, 'localize_printed_scripts' ), 5 );
57 add_action( 'wp_print_footer_scripts', array( __CLASS__, 'localize_printed_scripts' ), 5 );
58 add_action( 'enqueue_block_assets', array( __CLASS__, 'enqueue_block_assets' ) );
59 }
60
61 /**
62 * Get styles for the frontend.
63 *
64 * @return array
65 */
66 public static function get_styles() {
67 $version = Constants::get_constant( 'WC_VERSION' );
68
69 /**
70 * Filter list of WooCommerce styles to enqueue.
71 *
72 * @since 2.1.0
73 * @param array List of default WooCommerce styles.
74 * @return array List of styles to enqueue.
75 */
76 $styles = apply_filters(
77 'woocommerce_enqueue_styles',
78 array(
79 'woocommerce-layout' => array(
80 'src' => self::get_asset_url( 'assets/css/woocommerce-layout.css' ),
81 'deps' => '',
82 'version' => $version,
83 'media' => 'all',
84 'has_rtl' => true,
85 ),
86 'woocommerce-smallscreen' => array(
87 'src' => self::get_asset_url( 'assets/css/woocommerce-smallscreen.css' ),
88 'deps' => 'woocommerce-layout',
89 'version' => $version,
90 'media' => 'only screen and (max-width: ' . apply_filters( 'woocommerce_style_smallscreen_breakpoint', '768px' ) . ')',
91 'has_rtl' => true,
92 ),
93 'woocommerce-general' => array(
94 'src' => self::get_asset_url( 'assets/css/woocommerce.css' ),
95 'deps' => '',
96 'version' => $version,
97 'media' => 'all',
98 'has_rtl' => true,
99 ),
100 )
101 );
102 return is_array( $styles ) ? array_filter( $styles ) : array();
103 }
104
105 /**
106 * Enqueue styles for block assets (both editor and frontend).
107 * This ensures compatibility with WordPress 6.9+ requirements.
108 */
109 public static function enqueue_block_assets() {
110 if ( ! wp_is_block_theme() ) {
111 return;
112 }
113
114 $version = Constants::get_constant( 'WC_VERSION' );
115
116 wp_enqueue_style(
117 'woocommerce-blocktheme',
118 self::get_asset_url( 'assets/css/woocommerce-blocktheme.css' ),
119 array(),
120 $version,
121 'all'
122 );
123
124 wp_style_add_data( 'woocommerce-blocktheme', 'rtl', 'replace' );
125 }
126
127 /**
128 * Return asset URL.
129 *
130 * @param string $path Assets path.
131 * @return string
132 */
133 private static function get_asset_url( $path ) {
134 return apply_filters( 'woocommerce_get_asset_url', plugins_url( $path, WC_PLUGIN_FILE ), $path );
135 }
136
137 /**
138 * Register a script for use.
139 *
140 * @uses wp_register_script()
141 * @param string $handle Name of the script. Should be unique.
142 * @param string $path Full URL of the script, or path of the script relative to the WordPress root directory.
143 * @param string[] $deps An array of registered script handles this script depends on.
144 * @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.
145 * @param boolean $in_footer Whether to enqueue the script before </body> instead of in the <head>. Default 'false'.
146 */
147 private static function register_script( $handle, $path, $deps = array( 'jquery' ), $version = WC_VERSION, $in_footer = array( 'strategy' => 'defer' ) ) {
148 self::$registered_scripts[] = $handle;
149 wp_register_script( $handle, $path, $deps, $version, $in_footer );
150 }
151
152 /**
153 * Register and enqueue a script for use.
154 *
155 * @uses wp_enqueue_script()
156 * @param string $handle Name of the script. Should be unique.
157 * @param string $path Full URL of the script, or path of the script relative to the WordPress root directory.
158 * @param string[] $deps An array of registered script handles this script depends on.
159 * @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.
160 * @param boolean $in_footer Whether to enqueue the script before </body> instead of in the <head>. Default 'false'.
161 */
162 private static function enqueue_script( $handle, $path = '', $deps = array( 'jquery' ), $version = WC_VERSION, $in_footer = array( 'strategy' => 'defer' ) ) {
163 if ( ! in_array( $handle, self::$registered_scripts, true ) && $path ) {
164 self::register_script( $handle, $path, $deps, $version, $in_footer );
165 }
166 wp_enqueue_script( $handle );
167 }
168
169 /**
170 * Register a style for use.
171 *
172 * @uses wp_register_style()
173 * @param string $handle Name of the stylesheet. Should be unique.
174 * @param string $path Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
175 * @param string[] $deps An array of registered stylesheet handles this stylesheet depends on.
176 * @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.
177 * @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)'.
178 * @param boolean $has_rtl If has RTL version to load too.
179 */
180 private static function register_style( $handle, $path, $deps = array(), $version = WC_VERSION, $media = 'all', $has_rtl = false ) {
181 self::$styles[] = $handle;
182 wp_register_style( $handle, $path, $deps, $version, $media );
183
184 if ( $has_rtl ) {
185 wp_style_add_data( $handle, 'rtl', 'replace' );
186 }
187 }
188
189 /**
190 * Register and enqueue a styles for use.
191 *
192 * @uses wp_enqueue_style()
193 * @param string $handle Name of the stylesheet. Should be unique.
194 * @param string $path Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
195 * @param string[] $deps An array of registered stylesheet handles this stylesheet depends on.
196 * @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.
197 * @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)'.
198 * @param boolean $has_rtl If has RTL version to load too.
199 */
200 private static function enqueue_style( $handle, $path = '', $deps = array(), $version = WC_VERSION, $media = 'all', $has_rtl = false ) {
201 if ( ! in_array( $handle, self::$styles, true ) && $path ) {
202 self::register_style( $handle, $path, $deps, $version, $media, $has_rtl );
203 }
204 wp_enqueue_style( $handle );
205 }
206
207 /**
208 * Get scripts for the frontend.
209 *
210 * @return array
211 */
212 private static function get_scripts(): array {
213 $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min';
214 $version = Constants::get_constant( 'WC_VERSION' );
215
216 $scripts = array(
217 'selectWoo' => array(
218 'src' => self::get_asset_url( 'assets/js/selectWoo/selectWoo.full' . $suffix . '.js' ),
219 'deps' => array( 'jquery' ),
220 'version' => '1.0.9-wc.' . $version,
221 ),
222 'wc-account-i18n' => array(
223 'src' => self::get_asset_url( 'assets/js/frontend/account-i18n' . $suffix . '.js' ),
224 'deps' => array( 'jquery' ),
225 'version' => $version,
226 ),
227 'wc-add-payment-method' => array(
228 'src' => self::get_asset_url( 'assets/js/frontend/add-payment-method' . $suffix . '.js' ),
229 'deps' => array( 'jquery', 'woocommerce' ),
230 'version' => $version,
231 ),
232 'wc-add-to-cart' => array(
233 'src' => self::get_asset_url( 'assets/js/frontend/add-to-cart' . $suffix . '.js' ),
234 'deps' => array( 'jquery', 'wc-jquery-blockui' ),
235 'version' => $version,
236 ),
237 'wc-add-to-cart-variation' => array(
238 'src' => self::get_asset_url( 'assets/js/frontend/add-to-cart-variation' . $suffix . '.js' ),
239 'deps' => array( 'jquery', 'wp-util', 'wc-jquery-blockui' ),
240 'version' => $version,
241 ),
242 'wc-address-i18n' => array(
243 'src' => self::get_asset_url( 'assets/js/frontend/address-i18n' . $suffix . '.js' ),
244 'deps' => array( 'jquery', 'wc-country-select' ),
245 'version' => $version,
246 ),
247 'wc-back-in-stock-form' => array(
248 'src' => self::get_asset_url( 'assets/js/frontend/back-in-stock-form' . $suffix . '.js' ),
249 'deps' => array( 'jquery' ),
250 'version' => $version,
251 ),
252 'wc-cart' => array(
253 'src' => self::get_asset_url( 'assets/js/frontend/cart' . $suffix . '.js' ),
254 'deps' => array( 'jquery', 'woocommerce', 'wc-country-select', 'wc-address-i18n' ),
255 'version' => $version,
256 ),
257 'wc-cart-fragments' => array(
258 'src' => self::get_asset_url( 'assets/js/frontend/cart-fragments' . $suffix . '.js' ),
259 'deps' => array( 'jquery', 'wc-js-cookie' ),
260 'version' => $version,
261 ),
262 'wc-checkout' => array(
263 'src' => self::get_asset_url( 'assets/js/frontend/checkout' . $suffix . '.js' ),
264 'deps' => array( 'jquery', 'woocommerce', 'wc-country-select', 'wc-address-i18n' ),
265 'version' => $version,
266 ),
267 'wc-country-select' => array(
268 'src' => self::get_asset_url( 'assets/js/frontend/country-select' . $suffix . '.js' ),
269 'deps' => array( 'jquery' ),
270 'version' => $version,
271 ),
272 'wc-credit-card-form' => array(
273 'src' => self::get_asset_url( 'assets/js/frontend/credit-card-form' . $suffix . '.js' ),
274 'deps' => array( 'jquery', 'wc-jquery-payment' ),
275 'version' => $version,
276 ),
277 'wc-dompurify' => array(
278 'src' => self::get_asset_url( 'assets/js/dompurify/purify' . $suffix . '.js' ),
279 'deps' => array(),
280 'version' => $version,
281 ),
282 'wc-flexslider' => array(
283 'src' => self::get_asset_url( 'assets/js/flexslider/jquery.flexslider' . $suffix . '.js' ),
284 'deps' => array( 'jquery' ),
285 'version' => '2.7.2-wc.' . $version,
286 'legacy_handle' => 'flexslider',
287 ),
288 'wc-geolocation' => array(
289 'src' => self::get_asset_url( 'assets/js/frontend/geolocation' . $suffix . '.js' ),
290 'deps' => array( 'jquery' ),
291 'version' => $version,
292 ),
293 'wc-jquery-blockui' => array(
294 'src' => self::get_asset_url( 'assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js' ),
295 'deps' => array( 'jquery' ),
296 'version' => '2.7.0-wc.' . $version,
297 'legacy_handle' => 'jquery-blockui',
298 ),
299 'wc-jquery-cookie' => array(
300 'src' => self::get_asset_url( 'assets/js/jquery-cookie/jquery.cookie' . $suffix . '.js' ),
301 'deps' => array( 'jquery' ),
302 'version' => '1.4.1-wc.' . $version,
303 'legacy_handle' => 'jquery-cookie',
304 ),
305 'wc-jquery-payment' => array(
306 'src' => self::get_asset_url( 'assets/js/jquery-payment/jquery.payment' . $suffix . '.js' ),
307 'deps' => array( 'jquery' ),
308 'version' => '3.0.0-wc.' . $version,
309 'legacy_handle' => 'jquery-payment',
310 ),
311 'wc-jquery-tiptip' => array(
312 'src' => self::get_asset_url( 'assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js' ),
313 'deps' => array( 'jquery', 'wc-dompurify' ),
314 'version' => $version,
315 'legacy_handle' => 'jquery-tiptip',
316 ),
317 'wc-js-cookie' => array(
318 'src' => self::get_asset_url( 'assets/js/js-cookie/js.cookie' . $suffix . '.js' ),
319 'deps' => array(),
320 'version' => '2.1.4-wc.' . $version,
321 'legacy_handle' => 'js-cookie',
322 ),
323 'wc-lost-password' => array(
324 'src' => self::get_asset_url( 'assets/js/frontend/lost-password' . $suffix . '.js' ),
325 'deps' => array( 'jquery', 'woocommerce' ),
326 'version' => $version,
327 ),
328 'wc-password-strength-meter' => array(
329 'src' => self::get_asset_url( 'assets/js/frontend/password-strength-meter' . $suffix . '.js' ),
330 'deps' => array( 'jquery', 'password-strength-meter' ),
331 'version' => $version,
332 ),
333 'wc-photoswipe' => array(
334 'src' => self::get_asset_url( 'assets/js/photoswipe/photoswipe' . $suffix . '.js' ),
335 'deps' => array(),
336 'version' => '4.1.1-wc.' . $version,
337 'legacy_handle' => 'photoswipe',
338 ),
339 'wc-photoswipe-ui-default' => array(
340 'src' => self::get_asset_url( 'assets/js/photoswipe/photoswipe-ui-default' . $suffix . '.js' ),
341 'deps' => array( 'wc-photoswipe' ),
342 'version' => '4.1.1-wc.' . $version,
343 'legacy_handle' => 'photoswipe-ui-default',
344 ),
345 'wc-prettyPhoto' => array( // deprecated.
346 'src' => self::get_asset_url( 'assets/js/prettyPhoto/jquery.prettyPhoto' . $suffix . '.js' ),
347 'deps' => array( 'jquery' ),
348 'version' => '3.1.6-wc.' . $version,
349 'legacy_handle' => 'prettyPhoto',
350 ),
351 'wc-prettyPhoto-init' => array( // deprecated.
352 'src' => self::get_asset_url( 'assets/js/prettyPhoto/jquery.prettyPhoto.init' . $suffix . '.js' ),
353 'deps' => array( 'jquery', 'wc-prettyPhoto' ),
354 'version' => $version,
355 'legacy_handle' => 'prettyPhoto-init',
356 ),
357 'wc-select2' => array(
358 'src' => self::get_asset_url( 'assets/js/select2/select2.full' . $suffix . '.js' ),
359 'deps' => array( 'jquery' ),
360 'version' => '4.0.3-wc.' . $version,
361 'legacy_handle' => 'select2',
362 ),
363 'wc-single-product' => array(
364 'src' => self::get_asset_url( 'assets/js/frontend/single-product' . $suffix . '.js' ),
365 'deps' => array( 'jquery' ),
366 'version' => $version,
367 ),
368 'wc-zoom' => array(
369 'src' => self::get_asset_url( 'assets/js/zoom/jquery.zoom' . $suffix . '.js' ),
370 'deps' => array( 'jquery' ),
371 'version' => '1.7.21-wc.' . $version,
372 'legacy_handle' => 'zoom',
373 ),
374 'woocommerce' => array(
375 'src' => self::get_asset_url( 'assets/js/frontend/woocommerce' . $suffix . '.js' ),
376 'deps' => array( 'jquery', 'wc-jquery-blockui', 'wc-js-cookie' ),
377 'version' => $version,
378 ),
379 );
380
381 if ( wc_string_to_bool( get_option( 'woocommerce_address_autocomplete_enabled', 'no' ) ) === true ) {
382 $scripts['wc-address-autocomplete-common'] = array(
383 'src' => self::get_asset_url( 'assets/js/frontend/utils/address-autocomplete-common' . $suffix . '.js' ),
384 'deps' => array(),
385 'version' => $version,
386 );
387
388 $scripts['wc-address-autocomplete'] = array(
389 'src' => self::get_asset_url( 'assets/js/frontend/address-autocomplete' . $suffix . '.js' ),
390 'deps' => array( 'wc-address-autocomplete-common', 'wc-dompurify' ),
391 'version' => $version,
392 );
393 }
394
395 return $scripts;
396 }
397
398 /**
399 * Register all WC scripts.
400 */
401 private static function register_scripts() {
402 $register_scripts = self::get_scripts();
403
404 foreach ( $register_scripts as $name => $props ) {
405 self::register_script( $name, $props['src'], $props['deps'], $props['version'] );
406
407 if ( isset( $props['legacy_handle'] ) ) {
408 self::register_script( $props['legacy_handle'], false, array( $name ), $props['version'], true );
409 }
410 }
411 }
412
413 /**
414 * Register all WC styles.
415 */
416 private static function register_styles() {
417 $version = Constants::get_constant( 'WC_VERSION' );
418
419 $register_styles = array(
420 'photoswipe' => array(
421 'src' => self::get_asset_url( 'assets/css/photoswipe/photoswipe.min.css' ),
422 'deps' => array(),
423 'version' => $version,
424 'has_rtl' => false,
425 ),
426 'photoswipe-default-skin' => array(
427 'src' => self::get_asset_url( 'assets/css/photoswipe/default-skin/default-skin.min.css' ),
428 'deps' => array( 'photoswipe' ),
429 'version' => $version,
430 'has_rtl' => false,
431 ),
432 'select2' => array(
433 'src' => self::get_asset_url( 'assets/css/select2.css' ),
434 'deps' => array(),
435 'version' => $version,
436 'has_rtl' => false,
437 ),
438 'woocommerce_prettyPhoto_css' => array( // deprecated.
439 'src' => self::get_asset_url( 'assets/css/prettyPhoto.css' ),
440 'deps' => array(),
441 'version' => $version,
442 'has_rtl' => true,
443 ),
444 );
445
446 if ( wc_string_to_bool( get_option( 'woocommerce_address_autocomplete_enabled', 'no' ) ) === true ) {
447 $register_styles['wc-address-autocomplete'] = array(
448 'src' => self::get_asset_url( 'assets/css/address-autocomplete.css' ),
449 'deps' => array(),
450 'version' => $version,
451 'has_rtl' => false,
452 );
453 }
454
455 foreach ( $register_styles as $name => $props ) {
456 self::register_style( $name, $props['src'], $props['deps'], $props['version'], 'all', $props['has_rtl'] );
457 }
458 }
459
460 /**
461 * Register/queue frontend scripts.
462 */
463 public static function load_scripts() {
464 global $post;
465
466 if ( ! did_action( 'before_woocommerce_init' ) ) {
467 return;
468 }
469
470 self::register_scripts();
471 self::register_styles();
472
473 if ( 'yes' === get_option( 'woocommerce_enable_ajax_add_to_cart' ) ) {
474 self::enqueue_script( 'wc-add-to-cart' );
475 }
476 if ( is_cart() ) {
477 self::enqueue_script( 'wc-cart' );
478 }
479 if ( is_cart() || is_checkout() || is_account_page() ) {
480 self::enqueue_script( 'selectWoo' );
481 self::enqueue_style( 'select2' );
482
483 // Password strength meter. Load in checkout, account login and edit account page.
484 if ( ( 'no' === get_option( 'woocommerce_registration_generate_password' ) && ! is_user_logged_in() ) || is_edit_account_page() || is_lost_password_page() ) {
485 self::enqueue_script( 'wc-password-strength-meter' );
486 }
487 }
488 if ( is_account_page() ) {
489 self::enqueue_script( 'wc-account-i18n' );
490 }
491 if ( is_checkout() ) {
492 self::enqueue_script( 'wc-checkout' );
493 }
494
495 if ( wc_string_to_bool( get_option( 'woocommerce_address_autocomplete_enabled', 'no' ) ) === true ) {
496 $address_provider_service = wc_get_container()->get( AddressProviderController::class );
497 if ( $address_provider_service && method_exists( $address_provider_service, 'get_providers' ) ) {
498 $registered_providers = $address_provider_service->get_providers();
499 if ( is_array( $registered_providers ) && count( $registered_providers ) > 0 ) {
500 // Always enqueue the common module if providers are registered.
501 self::enqueue_script( 'wc-address-autocomplete-common' );
502 self::enqueue_script( 'wc-address-autocomplete' );
503 self::enqueue_style( 'wc-address-autocomplete' );
504 }
505 }
506 }
507
508 if ( is_add_payment_method_page() ) {
509 self::enqueue_script( 'wc-add-payment-method' );
510 }
511 if ( is_lost_password_page() ) {
512 self::enqueue_script( 'wc-lost-password' );
513 }
514
515 // Load gallery scripts on product pages only if supported.
516 if ( ( is_product() && ! wp_is_block_theme() ) || ( ! empty( $post->post_content ) && strstr( $post->post_content, '[product_page' ) ) ) {
517 if ( current_theme_supports( 'wc-product-gallery-zoom' ) ) {
518 self::enqueue_script( 'wc-zoom' );
519 }
520 if ( current_theme_supports( 'wc-product-gallery-slider' ) ) {
521 self::enqueue_script( 'wc-flexslider' );
522 }
523 if ( current_theme_supports( 'wc-product-gallery-lightbox' ) ) {
524 self::enqueue_script( 'wc-photoswipe-ui-default' );
525 self::enqueue_style( 'photoswipe-default-skin' );
526 add_action( 'wp_footer', 'woocommerce_photoswipe' );
527 }
528
529 self::enqueue_script( 'wc-single-product' );
530 }
531
532 // Only enqueue the geolocation script if the Default Current Address is set to "Geolocate
533 // (with Page Caching Support) and outside of the cart, checkout, account and customizer preview.
534 if (
535 'geolocation_ajax' === get_option( 'woocommerce_default_customer_address' )
536 && ! ( is_cart() || is_account_page() || is_checkout() || is_customize_preview() )
537 ) {
538 $ua = strtolower( wc_get_user_agent() ); // Exclude common bots from geolocation by user agent.
539
540 if ( ! strstr( $ua, 'bot' ) && ! strstr( $ua, 'spider' ) && ! strstr( $ua, 'crawl' ) ) {
541 self::enqueue_script( 'wc-geolocation' );
542 }
543 }
544
545 // Global frontend scripts.
546 self::enqueue_script( 'woocommerce' );
547
548 // CSS Styles.
549 $enqueue_styles = self::get_styles();
550 if ( $enqueue_styles ) {
551 foreach ( $enqueue_styles as $handle => $args ) {
552 if ( ! isset( $args['has_rtl'] ) ) {
553 $args['has_rtl'] = false;
554 }
555
556 self::enqueue_style( $handle, $args['src'], $args['deps'], $args['version'], $args['media'], $args['has_rtl'] );
557 }
558 }
559
560 // Placeholder style.
561 wp_register_style( 'woocommerce-inline', false ); // phpcs:ignore
562 wp_enqueue_style( 'woocommerce-inline' );
563
564 if ( true === wc_string_to_bool( get_option( 'woocommerce_checkout_highlight_required_fields', 'yes' ) ) ) {
565 wp_add_inline_style( 'woocommerce-inline', '.woocommerce form .form-row .required { visibility: visible; }' );
566 } else {
567 wp_add_inline_style( 'woocommerce-inline', '.woocommerce form .form-row .required { visibility: hidden; }' );
568 }
569 }
570
571 /**
572 * Localize a WC script once.
573 *
574 * @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.
575 * @param string $handle Script handle the data will be attached to.
576 */
577 private static function localize_script( $handle ) {
578 if ( ! in_array( $handle, self::$wp_localize_scripts, true ) && wp_script_is( $handle ) ) {
579 $data = self::get_script_data( $handle );
580
581 if ( ! $data ) {
582 return;
583 }
584
585 $name = str_replace( '-', '_', $handle ) . '_params';
586 self::$wp_localize_scripts[] = $handle;
587 wp_localize_script( $handle, $name, apply_filters( $name, $data ) );
588 }
589 }
590
591 /**
592 * Return data for script handles.
593 *
594 * @param string $handle Script handle the data will be attached to.
595 * @return array|bool
596 */
597 private static function get_script_data( $handle ) {
598 global $wp;
599
600 switch ( $handle ) {
601 case 'woocommerce':
602 $params = array(
603 'ajax_url' => WC()->ajax_url(),
604 'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
605 'i18n_password_show' => esc_attr__( 'Show password', 'woocommerce' ),
606 'i18n_password_hide' => esc_attr__( 'Hide password', 'woocommerce' ),
607 );
608 break;
609 case 'wc-geolocation':
610 $params = array(
611 'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
612 'home_url' => remove_query_arg( 'lang', home_url() ), // FIX for WPML compatibility.
613 );
614 break;
615 case 'wc-single-product':
616 $params = array(
617 'i18n_required_rating_text' => esc_attr__( 'Please select a rating', 'woocommerce' ),
618 'i18n_rating_options' => array(
619 esc_attr__( '1 of 5 stars', 'woocommerce' ),
620 esc_attr__( '2 of 5 stars', 'woocommerce' ),
621 esc_attr__( '3 of 5 stars', 'woocommerce' ),
622 esc_attr__( '4 of 5 stars', 'woocommerce' ),
623 esc_attr__( '5 of 5 stars', 'woocommerce' ),
624 ),
625 'i18n_product_gallery_trigger_text' => esc_attr__( 'View full-screen image gallery', 'woocommerce' ),
626 'review_rating_required' => wc_review_ratings_required() ? 'yes' : 'no',
627 'flexslider' => apply_filters(
628 'woocommerce_single_product_carousel_options',
629 array(
630 'rtl' => is_rtl(),
631 'animation' => 'slide',
632 'smoothHeight' => true,
633 'directionNav' => false,
634 'controlNav' => 'thumbnails',
635 'slideshow' => false,
636 'animationSpeed' => 500,
637 'animationLoop' => false, // Breaks photoswipe pagination if true.
638 'allowOneSlide' => false,
639 )
640 ),
641 'zoom_enabled' => apply_filters( 'woocommerce_single_product_zoom_enabled', get_theme_support( 'wc-product-gallery-zoom' ) ),
642 'zoom_options' => apply_filters( 'woocommerce_single_product_zoom_options', array() ),
643 'photoswipe_enabled' => apply_filters( 'woocommerce_single_product_photoswipe_enabled', get_theme_support( 'wc-product-gallery-lightbox' ) ),
644 'photoswipe_options' => apply_filters(
645 'woocommerce_single_product_photoswipe_options',
646 array(
647 'shareEl' => false,
648 'closeOnScroll' => false,
649 'history' => false,
650 'hideAnimationDuration' => 0,
651 'showAnimationDuration' => 0,
652 )
653 ),
654 'flexslider_enabled' => apply_filters( 'woocommerce_single_product_flexslider_enabled', get_theme_support( 'wc-product-gallery-slider' ) ),
655 );
656 break;
657 case 'wc-checkout':
658 $params = array(
659 'ajax_url' => WC()->ajax_url(),
660 'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
661 'update_order_review_nonce' => wp_create_nonce( 'update-order-review' ),
662 'apply_coupon_nonce' => wp_create_nonce( 'apply-coupon' ),
663 'remove_coupon_nonce' => wp_create_nonce( 'remove-coupon' ),
664 'option_guest_checkout' => get_option( 'woocommerce_enable_guest_checkout' ),
665 'checkout_url' => WC_AJAX::get_endpoint( 'checkout' ),
666 'is_checkout' => is_checkout() && empty( $wp->query_vars['order-pay'] ) && ! isset( $wp->query_vars['order-received'] ) ? 1 : 0,
667 'debug_mode' => Constants::is_true( 'WP_DEBUG' ),
668 /* translators: %s: Order history URL on My Account section */
669 'i18n_checkout_error' => sprintf( esc_attr__( 'There was an error processing your order. Please check for any charges in your payment method and review your <a href="%s">order history</a> before placing the order again.', 'woocommerce' ), esc_url( wc_get_account_endpoint_url( 'orders' ) ) ),
670 );
671 break;
672 case 'wc-address-autocomplete-common':
673 $providers = array();
674 try {
675 $providers = wc_get_container()->get( AddressProviderController::class )->get_providers();
676 } catch ( Throwable $e ) {
677 wc_get_logger()->error( 'Could not get address providers for wc-address-autocomplete script: ' . $e->getMessage(), array( 'source' => 'address-autocomplete' ) );
678 }
679 $params = array(
680 'address_providers' => wp_json_encode(
681 array_map(
682 function ( $provider ) {
683 // Escape provider data before sending to frontend.
684 return array(
685 'id' => $provider->id,
686 'name' => $provider->name,
687 'branding_html' => wp_kses(
688 trim( (string) ( $provider->branding_html ?? '' ) ),
689 'post'
690 ),
691 );
692 },
693 $providers
694 ),
695 JSON_HEX_TAG | JSON_UNESCAPED_SLASHES
696 ),
697 );
698 break;
699 case 'wc-address-i18n':
700 $params = array(
701 'locale' => wp_json_encode( WC()->countries->get_country_locale(), JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
702 'locale_fields' => wp_json_encode( WC()->countries->get_country_locale_field_selectors(), JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
703 'i18n_required_text' => esc_attr__( 'required', 'woocommerce' ),
704 'i18n_optional_text' => esc_html__( 'optional', 'woocommerce' ),
705 );
706 break;
707 case 'wc-cart':
708 $params = array(
709 'ajax_url' => WC()->ajax_url(),
710 'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
711 'update_shipping_method_nonce' => wp_create_nonce( 'update-shipping-method' ),
712 'apply_coupon_nonce' => wp_create_nonce( 'apply-coupon' ),
713 'remove_coupon_nonce' => wp_create_nonce( 'remove-coupon' ),
714 );
715 break;
716 case 'wc-cart-fragments':
717 $params = array(
718 'ajax_url' => WC()->ajax_url(),
719 'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
720 '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() ) ),
721 'fragment_name' => apply_filters( 'woocommerce_cart_fragment_name', 'wc_fragments_' . md5( get_current_blog_id() . '_' . get_site_url( get_current_blog_id(), '/' ) . get_template() ) ),
722 'request_timeout' => 5000,
723 );
724 break;
725 case 'wc-add-to-cart':
726 $params = array(
727 'ajax_url' => WC()->ajax_url(),
728 'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
729 'i18n_view_cart' => esc_attr__( 'View cart', 'woocommerce' ),
730 'cart_url' => apply_filters( 'woocommerce_add_to_cart_redirect', wc_get_cart_url(), null ),
731 'is_cart' => is_cart(),
732 'cart_redirect_after_add' => get_option( 'woocommerce_cart_redirect_after_add' ),
733 );
734 break;
735 case 'wc-add-to-cart-variation':
736 // We also need the wp.template for this script :).
737 wc_get_template( 'single-product/add-to-cart/variation.php' );
738
739 $params = array(
740 'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
741 'i18n_no_matching_variations_text' => esc_attr__( 'Sorry, no products matched your selection. Please choose a different combination.', 'woocommerce' ),
742 'i18n_make_a_selection_text' => esc_attr__( 'Please select some product options before adding this product to your cart.', 'woocommerce' ),
743 'i18n_unavailable_text' => esc_attr__( 'Sorry, this product is unavailable. Please choose a different combination.', 'woocommerce' ),
744 'i18n_reset_alert_text' => esc_attr__( 'Your selection has been reset. Please select some product options before adding this product to your cart.', 'woocommerce' ),
745 );
746 break;
747 case 'wc-country-select':
748 $params = array(
749 'countries' => wp_json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ), JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
750 'i18n_select_state_text' => esc_attr__( 'Select an option&hellip;', 'woocommerce' ),
751 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ),
752 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ),
753 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ),
754 'i18n_input_too_short_n' => _x( 'Please enter %qty% or more characters', 'enhanced select', 'woocommerce' ),
755 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'woocommerce' ),
756 'i18n_input_too_long_n' => _x( 'Please delete %qty% characters', 'enhanced select', 'woocommerce' ),
757 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'woocommerce' ),
758 'i18n_selection_too_long_n' => _x( 'You can only select %qty% items', 'enhanced select', 'woocommerce' ),
759 'i18n_load_more' => _x( 'Loading more results&hellip;', 'enhanced select', 'woocommerce' ),
760 'i18n_searching' => _x( 'Searching&hellip;', 'enhanced select', 'woocommerce' ),
761 );
762 break;
763 case 'wc-password-strength-meter':
764 $params = array(
765 'min_password_strength' => apply_filters( 'woocommerce_min_password_strength', 3 ),
766 'stop_checkout' => apply_filters( 'woocommerce_enforce_password_strength_meter_on_checkout', false ),
767 'i18n_password_error' => esc_attr__( 'Please enter a stronger password.', 'woocommerce' ),
768 'i18n_password_hint' => esc_attr( wp_get_password_hint() ),
769 );
770 break;
771 default:
772 $params = false;
773 }
774
775 $params = apply_filters_deprecated( $handle . '_params', array( $params ), '3.0.0', 'woocommerce_get_script_data' );
776
777 return apply_filters( 'woocommerce_get_script_data', $params, $handle );
778 }
779
780 /**
781 * Localize scripts only when enqueued.
782 */
783 public static function localize_printed_scripts() {
784 foreach ( self::$registered_scripts as $handle ) {
785 self::localize_script( $handle );
786 }
787 }
788 }
789
790 WC_Frontend_Scripts::init();
791