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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 months ago admin 3 months ago blocks 10 months ago cli 7 months ago customizer 3 months ago data-stores 3 months ago emails 3 months ago export 1 year ago gateways 3 months ago import 3 months ago integrations 2 years ago interfaces 3 months ago legacy 3 months ago libraries 1 year ago log-handlers 1 year ago payment-tokens 5 years ago product-usage 1 year ago queue 3 months ago react-admin 3 months ago rest-api 3 months ago shipping 3 months ago shortcodes 3 months ago theme-support 2 years ago tracks 3 months ago traits 5 years ago walkers 5 years ago wccom-site 9 months ago widgets 6 months ago class-wc-ajax.php 3 months ago class-wc-auth.php 1 year ago class-wc-autoloader.php 7 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 3 months ago class-wc-cache-helper.php 7 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 3 months ago class-wc-checkout.php 3 months ago class-wc-cli.php 9 months ago class-wc-comments.php 3 months ago class-wc-countries.php 3 months ago class-wc-coupon.php 3 months ago class-wc-customer-download-log.php 5 years ago class-wc-customer-download.php 1 year ago class-wc-customer.php 3 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 3 months ago class-wc-embed.php 1 year ago class-wc-form-handler.php 4 months ago class-wc-frontend-scripts.php 3 months ago class-wc-geo-ip.php 7 months ago class-wc-geolite-integration.php 6 years ago class-wc-geolocation.php 3 months ago class-wc-https.php 2 years ago class-wc-install.php 3 months ago class-wc-integrations.php 5 years ago class-wc-log-levels.php 2 years ago class-wc-logger.php 3 months ago class-wc-meta-data.php 4 years ago class-wc-order-factory.php 3 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 3 months ago class-wc-order-refund.php 1 year ago class-wc-order.php 3 months ago class-wc-payment-gateways.php 4 months ago class-wc-payment-tokens.php 3 years ago class-wc-post-data.php 3 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 3 months ago class-wc-product-download.php 3 months ago class-wc-product-external.php 1 year ago class-wc-product-factory.php 3 months ago class-wc-product-grouped.php 3 months ago class-wc-product-query.php 3 months ago class-wc-product-simple.php 10 months ago class-wc-product-variable.php 3 months ago class-wc-product-variation.php 1 year ago class-wc-query.php 3 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 7 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 3 months ago class-wc-tax.php 3 months ago class-wc-template-loader.php 6 months ago class-wc-tracker.php 7 months ago class-wc-validation.php 2 years ago class-wc-webhook.php 7 months ago class-woocommerce.php 3 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 3 months ago wc-coupon-functions.php 4 months ago wc-deprecated-functions.php 3 months ago wc-formatting-functions.php 6 months ago wc-interactivity-api-functions.php 3 months ago wc-notice-functions.php 4 months ago wc-order-functions.php 3 months ago wc-order-item-functions.php 3 years ago wc-order-step-logger-functions.php 3 months ago wc-page-functions.php 1 year ago wc-product-functions.php 3 months ago wc-rest-functions.php 6 months ago wc-stock-functions.php 6 months ago wc-template-functions.php 3 months ago wc-template-hooks.php 9 months ago wc-term-functions.php 6 months ago wc-update-functions.php 3 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
833 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', 'wc-custom-place-order-button' ),
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(
265 'jquery',
266 'woocommerce',
267 'wc-country-select',
268 'wc-address-i18n',
269 'wc-custom-place-order-button',
270 ),
271 'version' => $version,
272 ),
273 'wc-country-select' => array(
274 'src' => self::get_asset_url( 'assets/js/frontend/country-select' . $suffix . '.js' ),
275 'deps' => array( 'jquery' ),
276 'version' => $version,
277 ),
278 'wc-credit-card-form' => array(
279 'src' => self::get_asset_url( 'assets/js/frontend/credit-card-form' . $suffix . '.js' ),
280 'deps' => array( 'jquery', 'wc-jquery-payment' ),
281 'version' => $version,
282 ),
283 'wc-custom-place-order-button' => array(
284 'src' => self::get_asset_url( 'assets/js/frontend/utils/custom-place-order-button' . $suffix . '.js' ),
285 'deps' => array( 'jquery' ),
286 'version' => $version,
287 ),
288 'wc-dompurify' => array(
289 'src' => self::get_asset_url( 'assets/js/dompurify/purify' . $suffix . '.js' ),
290 'deps' => array(),
291 'version' => $version,
292 ),
293 'wc-flexslider' => array(
294 'src' => self::get_asset_url( 'assets/js/flexslider/jquery.flexslider' . $suffix . '.js' ),
295 'deps' => array( 'jquery' ),
296 'version' => '2.7.2-wc.' . $version,
297 'legacy_handle' => 'flexslider',
298 ),
299 'wc-geolocation' => array(
300 'src' => self::get_asset_url( 'assets/js/frontend/geolocation' . $suffix . '.js' ),
301 'deps' => array( 'jquery' ),
302 'version' => $version,
303 ),
304 'wc-jquery-blockui' => array(
305 'src' => self::get_asset_url( 'assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js' ),
306 'deps' => array( 'jquery' ),
307 'version' => '2.7.0-wc.' . $version,
308 'legacy_handle' => 'jquery-blockui',
309 ),
310 'wc-jquery-cookie' => array(
311 'src' => self::get_asset_url( 'assets/js/jquery-cookie/jquery.cookie' . $suffix . '.js' ),
312 'deps' => array( 'jquery' ),
313 'version' => '1.4.1-wc.' . $version,
314 'legacy_handle' => 'jquery-cookie',
315 ),
316 'wc-jquery-payment' => array(
317 'src' => self::get_asset_url( 'assets/js/jquery-payment/jquery.payment' . $suffix . '.js' ),
318 'deps' => array( 'jquery' ),
319 'version' => '3.0.0-wc.' . $version,
320 'legacy_handle' => 'jquery-payment',
321 ),
322 'wc-jquery-tiptip' => array(
323 'src' => self::get_asset_url( 'assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js' ),
324 'deps' => array( 'jquery', 'wc-dompurify' ),
325 'version' => $version,
326 'legacy_handle' => 'jquery-tiptip',
327 ),
328 'wc-js-cookie' => array(
329 'src' => self::get_asset_url( 'assets/js/js-cookie/js.cookie' . $suffix . '.js' ),
330 'deps' => array(),
331 'version' => '2.1.4-wc.' . $version,
332 'legacy_handle' => 'js-cookie',
333 ),
334 'wc-lost-password' => array(
335 'src' => self::get_asset_url( 'assets/js/frontend/lost-password' . $suffix . '.js' ),
336 'deps' => array( 'jquery', 'woocommerce' ),
337 'version' => $version,
338 ),
339 'wc-password-strength-meter' => array(
340 'src' => self::get_asset_url( 'assets/js/frontend/password-strength-meter' . $suffix . '.js' ),
341 'deps' => array( 'jquery', 'password-strength-meter' ),
342 'version' => $version,
343 ),
344 'wc-photoswipe' => array(
345 'src' => self::get_asset_url( 'assets/js/photoswipe/photoswipe' . $suffix . '.js' ),
346 'deps' => array(),
347 'version' => '4.1.1-wc.' . $version,
348 'legacy_handle' => 'photoswipe',
349 ),
350 'wc-photoswipe-ui-default' => array(
351 'src' => self::get_asset_url( 'assets/js/photoswipe/photoswipe-ui-default' . $suffix . '.js' ),
352 'deps' => array( 'wc-photoswipe' ),
353 'version' => '4.1.1-wc.' . $version,
354 'legacy_handle' => 'photoswipe-ui-default',
355 ),
356 'wc-prettyPhoto' => array( // deprecated.
357 'src' => self::get_asset_url( 'assets/js/prettyPhoto/jquery.prettyPhoto' . $suffix . '.js' ),
358 'deps' => array( 'jquery' ),
359 'version' => '3.1.6-wc.' . $version,
360 'legacy_handle' => 'prettyPhoto',
361 ),
362 'wc-prettyPhoto-init' => array( // deprecated.
363 'src' => self::get_asset_url( 'assets/js/prettyPhoto/jquery.prettyPhoto.init' . $suffix . '.js' ),
364 'deps' => array( 'jquery', 'wc-prettyPhoto' ),
365 'version' => $version,
366 'legacy_handle' => 'prettyPhoto-init',
367 ),
368 'wc-select2' => array(
369 'src' => self::get_asset_url( 'assets/js/select2/select2.full' . $suffix . '.js' ),
370 'deps' => array( 'jquery' ),
371 'version' => '4.0.3-wc.' . $version,
372 'legacy_handle' => 'select2',
373 ),
374 'wc-single-product' => array(
375 'src' => self::get_asset_url( 'assets/js/frontend/single-product' . $suffix . '.js' ),
376 'deps' => array( 'jquery' ),
377 'version' => $version,
378 ),
379 'wc-zoom' => array(
380 'src' => self::get_asset_url( 'assets/js/zoom/jquery.zoom' . $suffix . '.js' ),
381 'deps' => array( 'jquery' ),
382 'version' => '1.7.21-wc.' . $version,
383 'legacy_handle' => 'zoom',
384 ),
385 'woocommerce' => array(
386 'src' => self::get_asset_url( 'assets/js/frontend/woocommerce' . $suffix . '.js' ),
387 'deps' => array( 'jquery', 'wc-jquery-blockui', 'wc-js-cookie' ),
388 'version' => $version,
389 ),
390 );
391
392 if ( wc_string_to_bool( get_option( 'woocommerce_address_autocomplete_enabled', 'no' ) ) === true ) {
393 $scripts['wc-address-autocomplete-common'] = array(
394 'src' => self::get_asset_url( 'assets/js/frontend/utils/address-autocomplete-common' . $suffix . '.js' ),
395 'deps' => array(),
396 'version' => $version,
397 );
398
399 $scripts['wc-address-autocomplete'] = array(
400 'src' => self::get_asset_url( 'assets/js/frontend/address-autocomplete' . $suffix . '.js' ),
401 'deps' => array( 'wc-address-autocomplete-common', 'wc-dompurify' ),
402 'version' => $version,
403 );
404 }
405
406 return $scripts;
407 }
408
409 /**
410 * Register all WC scripts.
411 */
412 private static function register_scripts() {
413 $register_scripts = self::get_scripts();
414
415 foreach ( $register_scripts as $name => $props ) {
416 self::register_script( $name, $props['src'], $props['deps'], $props['version'] );
417
418 if ( isset( $props['legacy_handle'] ) ) {
419 self::register_script( $props['legacy_handle'], false, array( $name ), $props['version'], true );
420 }
421 }
422 }
423
424 /**
425 * Register all WC styles.
426 */
427 private static function register_styles() {
428 $version = Constants::get_constant( 'WC_VERSION' );
429
430 $register_styles = array(
431 'photoswipe' => array(
432 'src' => self::get_asset_url( 'assets/css/photoswipe/photoswipe.min.css' ),
433 'deps' => array(),
434 'version' => $version,
435 'has_rtl' => false,
436 ),
437 'photoswipe-default-skin' => array(
438 'src' => self::get_asset_url( 'assets/css/photoswipe/default-skin/default-skin.min.css' ),
439 'deps' => array( 'photoswipe' ),
440 'version' => $version,
441 'has_rtl' => false,
442 ),
443 'select2' => array(
444 'src' => self::get_asset_url( 'assets/css/select2.css' ),
445 'deps' => array(),
446 'version' => $version,
447 'has_rtl' => false,
448 ),
449 'woocommerce_prettyPhoto_css' => array( // deprecated.
450 'src' => self::get_asset_url( 'assets/css/prettyPhoto.css' ),
451 'deps' => array(),
452 'version' => $version,
453 'has_rtl' => true,
454 ),
455 );
456
457 if ( wc_string_to_bool( get_option( 'woocommerce_address_autocomplete_enabled', 'no' ) ) === true ) {
458 $register_styles['wc-address-autocomplete'] = array(
459 'src' => self::get_asset_url( 'assets/css/address-autocomplete.css' ),
460 'deps' => array(),
461 'version' => $version,
462 'has_rtl' => false,
463 );
464 }
465
466 foreach ( $register_styles as $name => $props ) {
467 self::register_style( $name, $props['src'], $props['deps'], $props['version'], 'all', $props['has_rtl'] );
468 }
469 }
470
471 /**
472 * Register/queue frontend scripts.
473 */
474 public static function load_scripts() {
475 global $post;
476
477 if ( ! did_action( 'before_woocommerce_init' ) ) {
478 return;
479 }
480
481 self::register_scripts();
482 self::register_styles();
483
484 if ( 'yes' === get_option( 'woocommerce_enable_ajax_add_to_cart' ) ) {
485 self::enqueue_script( 'wc-add-to-cart' );
486 }
487 if ( is_cart() ) {
488 self::enqueue_script( 'wc-cart' );
489 }
490 if ( is_cart() || is_checkout() || is_account_page() ) {
491 self::enqueue_script( 'selectWoo' );
492 self::enqueue_style( 'select2' );
493
494 // Password strength meter. Load in checkout, account login and edit account page.
495 if ( ( 'no' === get_option( 'woocommerce_registration_generate_password' ) && ! is_user_logged_in() ) || is_edit_account_page() || is_lost_password_page() ) {
496 self::enqueue_script( 'wc-password-strength-meter' );
497 }
498 }
499 if ( is_account_page() ) {
500 self::enqueue_script( 'wc-account-i18n' );
501 }
502 if ( is_checkout() ) {
503 self::enqueue_script( 'wc-checkout' );
504 }
505
506 if ( wc_string_to_bool( get_option( 'woocommerce_address_autocomplete_enabled', 'no' ) ) === true ) {
507 $address_provider_service = wc_get_container()->get( AddressProviderController::class );
508 if ( $address_provider_service && method_exists( $address_provider_service, 'get_providers' ) ) {
509 $registered_providers = $address_provider_service->get_providers();
510 if ( is_array( $registered_providers ) && count( $registered_providers ) > 0 ) {
511 // Always enqueue the common module if providers are registered.
512 self::enqueue_script( 'wc-address-autocomplete-common' );
513 self::enqueue_script( 'wc-address-autocomplete' );
514 self::enqueue_style( 'wc-address-autocomplete' );
515 }
516 }
517 }
518
519 if ( is_add_payment_method_page() ) {
520 self::enqueue_script( 'wc-add-payment-method' );
521 }
522 if ( is_lost_password_page() ) {
523 self::enqueue_script( 'wc-lost-password' );
524 }
525
526 // Load gallery scripts on product pages only if supported.
527 if ( ( is_product() && ! wp_is_block_theme() ) || ( ! empty( $post->post_content ) && strstr( $post->post_content, '[product_page' ) ) ) {
528 if ( current_theme_supports( 'wc-product-gallery-zoom' ) ) {
529 self::enqueue_script( 'wc-zoom' );
530 }
531 if ( current_theme_supports( 'wc-product-gallery-slider' ) ) {
532 self::enqueue_script( 'wc-flexslider' );
533 }
534 if ( current_theme_supports( 'wc-product-gallery-lightbox' ) ) {
535 self::enqueue_script( 'wc-photoswipe-ui-default' );
536 self::enqueue_style( 'photoswipe-default-skin' );
537 add_action( 'wp_footer', 'woocommerce_photoswipe' );
538 }
539
540 self::enqueue_script( 'wc-single-product' );
541 }
542
543 // Only enqueue the geolocation script if the Default Current Address is set to "Geolocate
544 // (with Page Caching Support) and outside of the cart, checkout, account and customizer preview.
545 if (
546 'geolocation_ajax' === get_option( 'woocommerce_default_customer_address' )
547 && ! ( is_cart() || is_account_page() || is_checkout() || is_customize_preview() )
548 ) {
549 $ua = strtolower( wc_get_user_agent() ); // Exclude common bots from geolocation by user agent.
550
551 if ( ! strstr( $ua, 'bot' ) && ! strstr( $ua, 'spider' ) && ! strstr( $ua, 'crawl' ) ) {
552 self::enqueue_script( 'wc-geolocation' );
553 }
554 }
555
556 // Global frontend scripts.
557 self::enqueue_script( 'woocommerce' );
558
559 // CSS Styles.
560 $enqueue_styles = self::get_styles();
561 if ( $enqueue_styles ) {
562 foreach ( $enqueue_styles as $handle => $args ) {
563 if ( ! isset( $args['has_rtl'] ) ) {
564 $args['has_rtl'] = false;
565 }
566
567 self::enqueue_style( $handle, $args['src'], $args['deps'], $args['version'], $args['media'], $args['has_rtl'] );
568 }
569 }
570
571 // Placeholder style.
572 wp_register_style( 'woocommerce-inline', false ); // phpcs:ignore
573 wp_enqueue_style( 'woocommerce-inline' );
574
575 if ( true === wc_string_to_bool( get_option( 'woocommerce_checkout_highlight_required_fields', 'yes' ) ) ) {
576 wp_add_inline_style( 'woocommerce-inline', '.woocommerce form .form-row .required { visibility: visible; }' );
577 } else {
578 wp_add_inline_style( 'woocommerce-inline', '.woocommerce form .form-row .required { visibility: hidden; }' );
579 }
580 }
581
582 /**
583 * Localize a WC script once.
584 *
585 * @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.
586 * @param string $handle Script handle the data will be attached to.
587 */
588 private static function localize_script( $handle ) {
589 if ( ! in_array( $handle, self::$wp_localize_scripts, true ) && wp_script_is( $handle ) ) {
590 $data = self::get_script_data( $handle );
591
592 if ( ! $data ) {
593 return;
594 }
595
596 $name = str_replace( '-', '_', $handle ) . '_params';
597 self::$wp_localize_scripts[] = $handle;
598 wp_localize_script( $handle, $name, apply_filters( $name, $data ) );
599 }
600 }
601
602 /**
603 * Return data for script handles.
604 *
605 * @param string $handle Script handle the data will be attached to.
606 * @return array|bool
607 */
608 private static function get_script_data( $handle ) {
609 global $wp;
610
611 switch ( $handle ) {
612 case 'woocommerce':
613 $params = array(
614 'ajax_url' => WC()->ajax_url(),
615 'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
616 'i18n_password_show' => esc_attr__( 'Show password', 'woocommerce' ),
617 'i18n_password_hide' => esc_attr__( 'Hide password', 'woocommerce' ),
618 );
619 break;
620 case 'wc-geolocation':
621 $params = array(
622 'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
623 'home_url' => remove_query_arg( 'lang', home_url() ), // FIX for WPML compatibility.
624 );
625 break;
626 case 'wc-single-product':
627 $params = array(
628 'i18n_required_rating_text' => esc_attr__( 'Please select a rating', 'woocommerce' ),
629 'i18n_rating_options' => array(
630 esc_attr__( '1 of 5 stars', 'woocommerce' ),
631 esc_attr__( '2 of 5 stars', 'woocommerce' ),
632 esc_attr__( '3 of 5 stars', 'woocommerce' ),
633 esc_attr__( '4 of 5 stars', 'woocommerce' ),
634 esc_attr__( '5 of 5 stars', 'woocommerce' ),
635 ),
636 'i18n_product_gallery_trigger_text' => esc_attr__( 'View full-screen image gallery', 'woocommerce' ),
637 'review_rating_required' => wc_review_ratings_required() ? 'yes' : 'no',
638 'flexslider' => apply_filters(
639 'woocommerce_single_product_carousel_options',
640 array(
641 'rtl' => is_rtl(),
642 'animation' => 'slide',
643 'smoothHeight' => true,
644 'directionNav' => false,
645 'controlNav' => 'thumbnails',
646 'slideshow' => false,
647 'animationSpeed' => 500,
648 'animationLoop' => false, // Breaks photoswipe pagination if true.
649 'allowOneSlide' => false,
650 )
651 ),
652 'zoom_enabled' => apply_filters( 'woocommerce_single_product_zoom_enabled', get_theme_support( 'wc-product-gallery-zoom' ) ),
653 'zoom_options' => apply_filters( 'woocommerce_single_product_zoom_options', array() ),
654 'photoswipe_enabled' => apply_filters( 'woocommerce_single_product_photoswipe_enabled', get_theme_support( 'wc-product-gallery-lightbox' ) ),
655 'photoswipe_options' => apply_filters(
656 'woocommerce_single_product_photoswipe_options',
657 array(
658 'shareEl' => false,
659 'closeOnScroll' => false,
660 'history' => false,
661 'hideAnimationDuration' => 0,
662 'showAnimationDuration' => 0,
663 )
664 ),
665 'flexslider_enabled' => apply_filters( 'woocommerce_single_product_flexslider_enabled', get_theme_support( 'wc-product-gallery-slider' ) ),
666 );
667 break;
668 case 'wc-checkout':
669 $params = array(
670 'ajax_url' => WC()->ajax_url(),
671 'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
672 'update_order_review_nonce' => wp_create_nonce( 'update-order-review' ),
673 'apply_coupon_nonce' => wp_create_nonce( 'apply-coupon' ),
674 'remove_coupon_nonce' => wp_create_nonce( 'remove-coupon' ),
675 'option_guest_checkout' => get_option( 'woocommerce_enable_guest_checkout' ),
676 'checkout_url' => WC_AJAX::get_endpoint( 'checkout' ),
677 'is_checkout' => is_checkout() && empty( $wp->query_vars['order-pay'] ) && ! isset( $wp->query_vars['order-received'] ) ? 1 : 0,
678 'debug_mode' => Constants::is_true( 'WP_DEBUG' ),
679 /* translators: %s: Order history URL on My Account section */
680 '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' ) ) ),
681 'gateways_with_custom_place_order_button' => self::get_gateways_with_custom_place_order_button(),
682 );
683 break;
684 case 'wc-address-autocomplete-common':
685 $providers = array();
686 try {
687 $providers = wc_get_container()->get( AddressProviderController::class )->get_providers();
688 } catch ( Throwable $e ) {
689 wc_get_logger()->error( 'Could not get address providers for wc-address-autocomplete script: ' . $e->getMessage(), array( 'source' => 'address-autocomplete' ) );
690 }
691 $params = array(
692 'address_providers' => wp_json_encode(
693 array_map(
694 function ( $provider ) {
695 // Escape provider data before sending to frontend.
696 return array(
697 'id' => $provider->id,
698 'name' => $provider->name,
699 'branding_html' => wp_kses(
700 trim( (string) ( $provider->branding_html ?? '' ) ),
701 'post'
702 ),
703 );
704 },
705 $providers
706 ),
707 JSON_HEX_TAG | JSON_UNESCAPED_SLASHES
708 ),
709 );
710 break;
711 case 'wc-address-i18n':
712 $params = array(
713 'locale' => wp_json_encode( WC()->countries->get_country_locale(), JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
714 'locale_fields' => wp_json_encode( WC()->countries->get_country_locale_field_selectors(), JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
715 'i18n_required_text' => esc_attr__( 'required', 'woocommerce' ),
716 'i18n_optional_text' => esc_html__( 'optional', 'woocommerce' ),
717 );
718 break;
719 case 'wc-cart':
720 $params = array(
721 'ajax_url' => WC()->ajax_url(),
722 'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
723 'update_shipping_method_nonce' => wp_create_nonce( 'update-shipping-method' ),
724 'apply_coupon_nonce' => wp_create_nonce( 'apply-coupon' ),
725 'remove_coupon_nonce' => wp_create_nonce( 'remove-coupon' ),
726 );
727 break;
728 case 'wc-cart-fragments':
729 $params = array(
730 'ajax_url' => WC()->ajax_url(),
731 'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
732 '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() ) ),
733 'fragment_name' => apply_filters( 'woocommerce_cart_fragment_name', 'wc_fragments_' . md5( get_current_blog_id() . '_' . get_site_url( get_current_blog_id(), '/' ) . get_template() ) ),
734 'request_timeout' => 5000,
735 );
736 break;
737 case 'wc-add-to-cart':
738 $params = array(
739 'ajax_url' => WC()->ajax_url(),
740 'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
741 'i18n_view_cart' => esc_attr__( 'View cart', 'woocommerce' ),
742 'cart_url' => apply_filters( 'woocommerce_add_to_cart_redirect', wc_get_cart_url(), null ),
743 'is_cart' => is_cart(),
744 'cart_redirect_after_add' => get_option( 'woocommerce_cart_redirect_after_add' ),
745 );
746 break;
747 case 'wc-add-payment-method':
748 $params = array(
749 'gateways_with_custom_place_order_button' => self::get_gateways_with_custom_place_order_button(),
750 );
751 break;
752 case 'wc-add-to-cart-variation':
753 // We also need the wp.template for this script :).
754 wc_get_template( 'single-product/add-to-cart/variation.php' );
755
756 $params = array(
757 'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
758 'i18n_no_matching_variations_text' => esc_attr__( 'Sorry, no products matched your selection. Please choose a different combination.', 'woocommerce' ),
759 'i18n_make_a_selection_text' => esc_attr__( 'Please select some product options before adding this product to your cart.', 'woocommerce' ),
760 'i18n_unavailable_text' => esc_attr__( 'Sorry, this product is unavailable. Please choose a different combination.', 'woocommerce' ),
761 'i18n_reset_alert_text' => esc_attr__( 'Your selection has been reset. Please select some product options before adding this product to your cart.', 'woocommerce' ),
762 );
763 break;
764 case 'wc-country-select':
765 $params = array(
766 'countries' => wp_json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ), JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
767 'i18n_select_state_text' => esc_attr__( 'Select an option&hellip;', 'woocommerce' ),
768 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ),
769 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ),
770 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ),
771 'i18n_input_too_short_n' => _x( 'Please enter %qty% or more characters', 'enhanced select', 'woocommerce' ),
772 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'woocommerce' ),
773 'i18n_input_too_long_n' => _x( 'Please delete %qty% characters', 'enhanced select', 'woocommerce' ),
774 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'woocommerce' ),
775 'i18n_selection_too_long_n' => _x( 'You can only select %qty% items', 'enhanced select', 'woocommerce' ),
776 'i18n_load_more' => _x( 'Loading more results&hellip;', 'enhanced select', 'woocommerce' ),
777 'i18n_searching' => _x( 'Searching&hellip;', 'enhanced select', 'woocommerce' ),
778 );
779 break;
780 case 'wc-password-strength-meter':
781 $params = array(
782 'min_password_strength' => apply_filters( 'woocommerce_min_password_strength', 3 ),
783 'stop_checkout' => apply_filters( 'woocommerce_enforce_password_strength_meter_on_checkout', false ),
784 'i18n_password_error' => esc_attr__( 'Please enter a stronger password.', 'woocommerce' ),
785 'i18n_password_hint' => esc_attr( wp_get_password_hint() ),
786 );
787 break;
788 default:
789 $params = false;
790 }
791
792 $params = apply_filters_deprecated( $handle . '_params', array( $params ), '3.0.0', 'woocommerce_get_script_data' );
793
794 return apply_filters( 'woocommerce_get_script_data', $params, $handle );
795 }
796
797 /**
798 * Get a list of payment gateway IDs that have custom place order buttons.
799 *
800 * @return array List of gateway IDs with custom place order buttons.
801 */
802 private static function get_gateways_with_custom_place_order_button() {
803 $gateways_with_custom_button = array();
804
805 if ( ! WC()->payment_gateways() ) {
806 return $gateways_with_custom_button;
807 }
808
809 $available_gateways = WC()->payment_gateways()->get_available_payment_gateways();
810
811 foreach ( $available_gateways as $gateway ) {
812 // phpcs:ignore Squiz.PHP.CommentedOutCode.Found -- Type hint for PHPStan.
813 /* @var WC_Payment_Gateway $gateway */
814 if ( true === $gateway->has_custom_place_order_button ) {
815 $gateways_with_custom_button[] = $gateway->id;
816 }
817 }
818
819 return $gateways_with_custom_button;
820 }
821
822 /**
823 * Localize scripts only when enqueued.
824 */
825 public static function localize_printed_scripts() {
826 foreach ( self::$registered_scripts as $handle ) {
827 self::localize_script( $handle );
828 }
829 }
830 }
831
832 WC_Frontend_Scripts::init();
833