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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 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 / admin / class-wc-admin-assets.php
woocommerce / includes / admin Last commit date
helper 2 months ago importers 1 year ago list-tables 1 month ago marketplace-suggestions 11 months ago meta-boxes 1 month ago notes 2 months ago plugin-updates 2 years ago reports 3 months ago settings 6 days ago views 1 month ago class-wc-admin-addons.php 9 months ago class-wc-admin-api-keys-table-list.php 2 years ago class-wc-admin-api-keys.php 11 months ago class-wc-admin-assets.php 1 month ago class-wc-admin-attributes.php 1 month ago class-wc-admin-brands.php 4 months ago class-wc-admin-customize.php 5 years ago class-wc-admin-dashboard-setup.php 1 month ago class-wc-admin-dashboard.php 4 months ago class-wc-admin-duplicate-product.php 5 months ago class-wc-admin-exporters.php 1 year ago class-wc-admin-help.php 2 years ago class-wc-admin-importers.php 11 months ago class-wc-admin-log-table-list.php 4 months ago class-wc-admin-marketplace-promotions.php 4 months ago class-wc-admin-menus.php 1 month ago class-wc-admin-meta-boxes.php 1 month ago class-wc-admin-notices.php 1 month ago class-wc-admin-permalink-settings.php 5 years ago class-wc-admin-pointers.php 3 years ago class-wc-admin-post-types.php 1 year ago class-wc-admin-profile.php 1 year ago class-wc-admin-reports.php 4 months ago class-wc-admin-settings.php 3 months ago class-wc-admin-setup-wizard.php 1 month ago class-wc-admin-status.php 1 year ago class-wc-admin-taxonomies.php 1 month ago class-wc-admin-upload-downloadable-product.php 2 years ago class-wc-admin-webhooks-table-list.php 1 month ago class-wc-admin-webhooks.php 1 month ago class-wc-admin.php 3 months ago wc-admin-functions.php 7 months ago wc-meta-box-functions.php 1 year ago woocommerce-legacy-reports.php 1 year ago
class-wc-admin-assets.php
966 lines
1 <?php
2 /**
3 * Load assets
4 *
5 * @package WooCommerce\Admin
6 * @version 3.7.0
7 */
8
9 use Automattic\Jetpack\Constants;
10 use Automattic\WooCommerce\Admin\Features\Features;
11 use Automattic\WooCommerce\Enums\OrderStatus;
12 use Automattic\WooCommerce\Enums\ProductType;
13 use Automattic\WooCommerce\Internal\Admin\Analytics;
14 use Automattic\WooCommerce\Internal\Admin\WCAdminAssets;
15 use Automattic\WooCommerce\Internal\CostOfGoodsSold\CostOfGoodsSoldController;
16
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit;
19 }
20
21 if ( ! class_exists( 'WC_Admin_Assets', false ) ) :
22
23 /**
24 * WC_Admin_Assets Class.
25 *
26 * These scripts are enqueued in the admin of the store. The registered script handles in this class
27 * can be used to enqueue the scripts in the admin by third party plugins and the handles will follow
28 * WooCommerce's L-1 support policy. Scripts registered outside of this class do not guarantee support
29 * and can be removed in future versions of WooCommerce.
30 */
31 class WC_Admin_Assets {
32
33 /**
34 * Hook in tabs.
35 */
36 public function __construct() {
37 add_action( 'admin_init', array( $this, 'register_scripts' ) );
38 add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ) );
39 add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
40 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_command_palette_assets' ) );
41 add_action( 'admin_notices', array( $this, 'render_lost_connection_notice' ) );
42 }
43
44 /**
45 * Render WordPress core's #lost-connection-notice markup on Woo admin
46 * screens that don't already get it for free.
47 *
48 * WP core renders this element on classic post-type edit pages (via
49 * edit-form-advanced.php), and wp-autosave.js toggles it in response
50 * to Heartbeat events. By echoing the same markup here and enqueueing
51 * the `autosave` script (see admin_scripts()), Woo admin screens
52 * inherit the same offline awareness without any new copy, styling,
53 * or behavior.
54 *
55 * Translation strings use the 'default' text domain so WP core's
56 * existing translations apply.
57 *
58 * Skipped on:
59 * - Classic post-type edit screens (WP core already renders the notice).
60 * - wc-admin React pages (they use their own layout rather than the
61 * standard admin_notices position).
62 *
63 * @return void
64 */
65 public function render_lost_connection_notice() {
66 $screen = get_current_screen();
67 if ( ! $screen ) {
68 return;
69 }
70
71 if ( 'post' === $screen->base ) {
72 return;
73 }
74
75 $is_wc_admin_page = class_exists( '\Automattic\WooCommerce\Admin\PageController' )
76 && \Automattic\WooCommerce\Admin\PageController::is_admin_page();
77 if ( $is_wc_admin_page ) {
78 return;
79 }
80
81 if ( ! in_array( $screen->id, wc_get_screen_ids(), true ) ) {
82 return;
83 }
84 ?>
85 <div id="lost-connection-notice" class="notice error hidden">
86 <p>
87 <span class="spinner"></span>
88 <strong><?php esc_html_e( 'Connection lost.' ); /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- Reusing WP core translation. */ ?></strong>
89 <?php esc_html_e( 'Saving has been disabled until you are reconnected.' ); /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- Reusing WP core translation. */ ?>
90 </p>
91 </div>
92 <?php
93 }
94
95 /**
96 * Enqueue styles.
97 */
98 public function admin_styles() {
99 $version = Constants::get_constant( 'WC_VERSION' );
100 $screen = get_current_screen();
101 $screen_id = $screen ? $screen->id : '';
102
103 // Register admin styles.
104 wp_register_style( 'woocommerce_admin_menu_styles', WC()->plugin_url() . '/assets/css/menu.css', array(), $version );
105 wp_register_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), $version );
106 wp_register_style( 'jquery-ui-style', WC()->plugin_url() . '/assets/css/jquery-ui/jquery-ui.min.css', array(), $version );
107 wp_register_style( 'woocommerce_admin_dashboard_styles', WC()->plugin_url() . '/assets/css/dashboard.css', array(), $version );
108 wp_register_style( 'woocommerce_admin_print_reports_styles', WC()->plugin_url() . '/assets/css/reports-print.css', array(), $version, 'print' );
109 wp_register_style( 'woocommerce_admin_marketplace_styles', WC()->plugin_url() . '/assets/css/marketplace-suggestions.css', array(), $version );
110 wp_register_style( 'woocommerce_admin_privacy_styles', WC()->plugin_url() . '/assets/css/privacy.css', array(), $version );
111
112 // Add RTL support for admin styles.
113 wp_style_add_data( 'woocommerce_admin_menu_styles', 'rtl', 'replace' );
114 wp_style_add_data( 'woocommerce_admin_styles', 'rtl', 'replace' );
115 wp_style_add_data( 'woocommerce_admin_dashboard_styles', 'rtl', 'replace' );
116 wp_style_add_data( 'woocommerce_admin_print_reports_styles', 'rtl', 'replace' );
117 wp_style_add_data( 'woocommerce_admin_marketplace_styles', 'rtl', 'replace' );
118 wp_style_add_data( 'woocommerce_admin_privacy_styles', 'rtl', 'replace' );
119
120 if ( $screen && $screen->is_block_editor() ) {
121 if ( ! wp_is_block_theme() ) {
122 wp_register_style( 'woocommerce-classictheme-editor-fonts', WC()->plugin_url() . '/assets/css/woocommerce-classictheme-editor-fonts.css', array(), $version );
123 wp_enqueue_style( 'woocommerce-classictheme-editor-fonts' );
124 }
125
126 $styles = WC_Frontend_Scripts::get_styles();
127
128 if ( $styles ) {
129 foreach ( $styles as $handle => $args ) {
130 wp_register_style(
131 $handle,
132 $args['src'],
133 $args['deps'],
134 $args['version'],
135 $args['media']
136 );
137
138 if ( ! isset( $args['has_rtl'] ) ) {
139 wp_style_add_data( $handle, 'rtl', 'replace' );
140 }
141
142 wp_enqueue_style( $handle );
143 }
144 }
145 }
146
147 // Sitewide menu CSS.
148 wp_enqueue_style( 'woocommerce_admin_menu_styles' );
149
150 // Admin styles for WC pages only.
151 if ( in_array( $screen_id, wc_get_screen_ids() ) ) {
152 wp_enqueue_style( 'woocommerce_admin_styles' );
153 wp_enqueue_style( 'jquery-ui-style' );
154 wp_enqueue_style( 'wp-color-picker' );
155 }
156
157 if ( in_array( $screen_id, array( 'dashboard' ) ) ) {
158 wp_enqueue_style( 'woocommerce_admin_dashboard_styles' );
159 }
160
161 if ( in_array( $screen_id, array( 'woocommerce_page_wc-reports', 'toplevel_page_wc-reports' ) ) ) {
162 wp_enqueue_style( 'woocommerce_admin_print_reports_styles' );
163 }
164
165 // Privacy Policy Guide css for back-compat.
166 if ( isset( $_GET['wp-privacy-policy-guide'] ) || in_array( $screen_id, array( 'privacy-policy-guide' ) ) ) {
167 wp_enqueue_style( 'woocommerce_admin_privacy_styles' );
168 }
169
170 // @deprecated 2.3.
171 if ( has_action( 'woocommerce_admin_css' ) ) {
172 /* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */
173 do_action( 'woocommerce_admin_css' );
174 /* phpcs: enable */
175 wc_deprecated_function( 'The woocommerce_admin_css action', '2.3', 'admin_enqueue_scripts' );
176 }
177
178 if ( WC_Marketplace_Suggestions::show_suggestions_for_screen( $screen_id ) ) {
179 wp_enqueue_style( 'woocommerce_admin_marketplace_styles' );
180 }
181 }
182
183 /**
184 * Get the scripts used for registration.
185 *
186 * @return array
187 */
188 private function get_scripts(): array {
189 $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min';
190 $version = Constants::get_constant( 'WC_VERSION' );
191 $plugin_url = WC()->plugin_url();
192
193 return array(
194 array(
195 'handle' => 'woocommerce_admin',
196 'path' => $plugin_url . '/assets/js/admin/woocommerce_admin' . $suffix . '.js',
197 'dependencies' => array( 'jquery', 'wc-jquery-blockui', 'jquery-ui-sortable', 'jquery-ui-widget', 'jquery-ui-core', 'wc-jquery-tiptip' ),
198 'version' => $version,
199 ),
200 array(
201 'legacy_handle' => 'jquery-blockui',
202 'handle' => 'wc-jquery-blockui',
203 'path' => $plugin_url . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js',
204 'dependencies' => array( 'jquery' ),
205 'version' => '2.70',
206 'args' => array(
207 'in_footer' => true,
208 ),
209 ),
210 array(
211 'legacy_handle' => 'jquery-tiptip',
212 'handle' => 'wc-jquery-tiptip',
213 'path' => $plugin_url . '/assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js',
214 'dependencies' => array( 'jquery', 'wc-dompurify' ),
215 'version' => $version,
216 'args' => array(
217 'in_footer' => true,
218 ),
219 ),
220 array(
221 'legacy_handle' => 'round',
222 'handle' => 'wc-round',
223 'path' => $plugin_url . '/assets/js/round/round' . $suffix . '.js',
224 'dependencies' => array( 'jquery' ),
225 'version' => $version,
226 ),
227 array(
228 'handle' => 'wc-admin-meta-boxes',
229 'path' => $plugin_url . '/assets/js/admin/meta-boxes' . $suffix . '.js',
230 'dependencies' => array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'wc-accounting', 'wc-round', 'wc-enhanced-select', 'plupload-all', 'wc-stupidtable', 'wc-jquery-tiptip', 'wc-jquery-blockui' ),
231 'version' => $version,
232 ),
233 array(
234 'legacy_handle' => 'qrcode',
235 'handle' => 'wc-qrcode',
236 'path' => $plugin_url . '/assets/js/jquery-qrcode/jquery.qrcode' . $suffix . '.js',
237 'dependencies' => array( 'jquery' ),
238 'version' => $version,
239 ),
240 array(
241 'legacy_handle' => 'stupidtable',
242 'handle' => 'wc-stupidtable',
243 'path' => $plugin_url . '/assets/js/stupidtable/stupidtable' . $suffix . '.js',
244 'dependencies' => array( 'jquery' ),
245 'version' => $version,
246 ),
247 array(
248 'legacy_handle' => 'serializejson',
249 'handle' => 'wc-serializejson',
250 'path' => $plugin_url . '/assets/js/jquery-serializejson/jquery.serializejson' . $suffix . '.js',
251 'dependencies' => array( 'jquery' ),
252 'version' => '2.8.1',
253 ),
254 array(
255 'legacy_handle' => 'flot',
256 'handle' => 'wc-flot',
257 'path' => $plugin_url . '/assets/js/jquery-flot/jquery.flot' . $suffix . '.js',
258 'dependencies' => array( 'jquery' ),
259 'version' => $version,
260 ),
261 array(
262 'legacy_handle' => 'flot-resize',
263 'handle' => 'wc-flot-resize',
264 'path' => $plugin_url . '/assets/js/jquery-flot/jquery.flot.resize' . $suffix . '.js',
265 'dependencies' => array( 'jquery', 'wc-flot' ),
266 'version' => $version,
267 ),
268 array(
269 'legacy_handle' => 'flot-time',
270 'handle' => 'wc-flot-time',
271 'path' => $plugin_url . '/assets/js/jquery-flot/jquery.flot.time' . $suffix . '.js',
272 'dependencies' => array( 'jquery', 'wc-flot' ),
273 'version' => $version,
274 ),
275 array(
276 'legacy_handle' => 'flot-pie',
277 'handle' => 'wc-flot-pie',
278 'path' => $plugin_url . '/assets/js/jquery-flot/jquery.flot.pie' . $suffix . '.js',
279 'dependencies' => array( 'jquery', 'wc-flot' ),
280 'version' => $version,
281 ),
282 array(
283 'legacy_handle' => 'flot-stack',
284 'handle' => 'wc-flot-stack',
285 'path' => $plugin_url . '/assets/js/jquery-flot/jquery.flot.stack' . $suffix . '.js',
286 'dependencies' => array( 'jquery', 'wc-flot' ),
287 'version' => $version,
288 ),
289 array(
290 'handle' => 'wc-settings-tax',
291 'path' => $plugin_url . '/assets/js/admin/settings-views-html-settings-tax' . $suffix . '.js',
292 'dependencies' => array( 'jquery', 'wp-util', 'underscore', 'backbone', 'wc-jquery-blockui' ),
293 'version' => $version,
294 ),
295 array(
296 'handle' => 'wc-backbone-modal',
297 'path' => $plugin_url . '/assets/js/admin/backbone-modal' . $suffix . '.js',
298 'dependencies' => array( 'underscore', 'backbone', 'wp-util' ),
299 'version' => $version,
300 ),
301 array(
302 'handle' => 'wc-shipping-zones',
303 'path' => $plugin_url . '/assets/js/admin/wc-shipping-zones' . $suffix . '.js',
304 'dependencies' => array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-enhanced-select', 'wc-backbone-modal' ),
305 'version' => $version,
306 ),
307 array(
308 'handle' => 'wc-shipping-zone-methods',
309 'path' => $plugin_url . '/assets/js/admin/wc-shipping-zone-methods' . $suffix . '.js',
310 'dependencies' => array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-backbone-modal' ),
311 'version' => $version,
312 ),
313 array(
314 'handle' => 'wc-shipping-classes',
315 'path' => $plugin_url . '/assets/js/admin/wc-shipping-classes' . $suffix . '.js',
316 'dependencies' => array( 'jquery', 'wp-util', 'underscore', 'backbone', 'wc-backbone-modal' ),
317 'version' => $version,
318 ),
319 array(
320 'handle' => 'wc-shipping-providers',
321 'path' => $plugin_url . '/assets/js/admin/wc-shipping-providers' . $suffix . '.js',
322 'dependencies' => array( 'jquery', 'wp-util', 'underscore', 'backbone', 'wc-backbone-modal' ),
323 'version' => $version,
324 ),
325 array(
326 'handle' => 'wc-clipboard',
327 'path' => $plugin_url . '/assets/js/admin/wc-clipboard' . $suffix . '.js',
328 'dependencies' => array( 'jquery' ),
329 'version' => $version,
330 ),
331 array(
332 'legacy_handle' => 'select2',
333 'handle' => 'wc-select2',
334 'path' => $plugin_url . '/assets/js/select2/select2.full' . $suffix . '.js',
335 'dependencies' => array( 'jquery' ),
336 'version' => '4.0.3',
337 ),
338 array(
339 'handle' => 'selectWoo',
340 'path' => $plugin_url . '/assets/js/selectWoo/selectWoo.full' . $suffix . '.js',
341 'dependencies' => array( 'jquery' ),
342 'version' => '1.0.6',
343 ),
344 array(
345 'handle' => 'wc-enhanced-select',
346 'path' => $plugin_url . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js',
347 'dependencies' => array( 'jquery', 'selectWoo' ),
348 'version' => $version,
349 ),
350 array(
351 'legacy_handle' => 'js-cookie',
352 'handle' => 'wc-js-cookie',
353 'path' => $plugin_url . '/assets/js/js-cookie/js.cookie' . $suffix . '.js',
354 'dependencies' => array(),
355 'version' => '2.1.4',
356 'args' => array(
357 'in_footer' => true,
358 ),
359 ),
360 array(
361 'legacy_handle' => 'dompurify',
362 'handle' => 'wc-dompurify',
363 'path' => $plugin_url . '/assets/js/dompurify/purify' . $suffix . '.js',
364 'dependencies' => array(),
365 'version' => $version,
366 ),
367 array(
368 'legacy_handle' => 'accounting',
369 'handle' => 'wc-accounting',
370 'path' => $plugin_url . '/assets/js/accounting/accounting' . $suffix . '.js',
371 'dependencies' => array( 'jquery' ),
372 'version' => '0.4.2',
373 ),
374 );
375 }
376
377 /**
378 * Register the scripts.
379 *
380 * These scripts are registered early to allow other
381 * plugins to take advantage of them by handle.
382 */
383 public function register_scripts() {
384 $scripts = $this->get_scripts();
385
386 foreach ( $scripts as $script ) {
387 wp_register_script(
388 $script['handle'],
389 $script['path'],
390 $script['dependencies'] ?? array(),
391 $script['version'] ?? null,
392 $script['args'] ?? array( 'in_footer' => false )
393 );
394
395 if ( isset( $script['legacy_handle'] ) ) {
396 wp_register_script(
397 $script['legacy_handle'],
398 false,
399 array( $script['handle'] ),
400 $script['version'] ?? null,
401 true
402 );
403 }
404 }
405
406 wp_localize_script(
407 'wc-enhanced-select',
408 'wc_enhanced_select_params',
409 array(
410 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ),
411 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ),
412 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ),
413 'i18n_input_too_short_n' => _x( 'Please enter %qty% or more characters', 'enhanced select', 'woocommerce' ),
414 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'woocommerce' ),
415 'i18n_input_too_long_n' => _x( 'Please delete %qty% characters', 'enhanced select', 'woocommerce' ),
416 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'woocommerce' ),
417 'i18n_selection_too_long_n' => _x( 'You can only select %qty% items', 'enhanced select', 'woocommerce' ),
418 'i18n_load_more' => _x( 'Loading more results&hellip;', 'enhanced select', 'woocommerce' ),
419 'i18n_searching' => _x( 'Searching&hellip;', 'enhanced select', 'woocommerce' ),
420 'ajax_url' => admin_url( 'admin-ajax.php' ),
421 'search_products_nonce' => wp_create_nonce( 'search-products' ),
422 'search_customers_nonce' => wp_create_nonce( 'search-customers' ),
423 'search_categories_nonce' => wp_create_nonce( 'search-categories' ),
424 'search_taxonomy_terms_nonce' => wp_create_nonce( 'search-taxonomy-terms' ),
425 'search_product_attributes_nonce' => wp_create_nonce( 'search-product-attributes' ),
426 'search_pages_nonce' => wp_create_nonce( 'search-pages' ),
427 'search_order_metakeys_nonce' => wp_create_nonce( 'search-order-metakeys' ),
428 )
429 );
430
431 wp_localize_script(
432 'wc-accounting',
433 'accounting_params',
434 array(
435 'mon_decimal_point' => wc_get_price_decimal_separator(),
436 )
437 );
438 }
439
440
441 /**
442 * Enqueue scripts.
443 */
444 public function admin_scripts() {
445 global $wp_query, $post, $theorder;
446
447 $screen = get_current_screen();
448 $screen_id = $screen ? $screen->id : '';
449 $wc_screen_id = 'woocommerce';
450 $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min';
451 $version = Constants::get_constant( 'WC_VERSION' );
452
453 wp_register_script( 'wc-orders', WC()->plugin_url() . '/assets/js/admin/wc-orders' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'wc-jquery-blockui' ), $version, array( 'in_footer' => false ) );
454 wp_localize_script(
455 'wc-orders',
456 'wc_orders_params',
457 array(
458 'ajax_url' => admin_url( 'admin-ajax.php' ),
459 'preview_nonce' => wp_create_nonce( 'woocommerce-preview-order' ),
460 )
461 );
462
463 // WooCommerce admin pages.
464 if ( in_array( $screen_id, wc_get_screen_ids() ) ) {
465 wp_enqueue_script( 'iris' );
466 wp_enqueue_script( 'woocommerce_admin' );
467 wp_enqueue_script( 'wc-enhanced-select' );
468
469 // Pair the #lost-connection-notice markup with core's autosave script.
470 // See render_lost_connection_notice() for scoping rationale.
471 $is_wc_admin_page = class_exists( '\Automattic\WooCommerce\Admin\PageController' )
472 && \Automattic\WooCommerce\Admin\PageController::is_admin_page();
473 if ( 'post' !== ( $screen->base ?? '' ) && ! $is_wc_admin_page ) {
474 wp_enqueue_script( 'autosave' );
475 }
476
477 wp_enqueue_script( 'jquery-ui-sortable' );
478 wp_enqueue_script( 'jquery-ui-autocomplete' );
479
480 $locale = localeconv();
481 $decimal_point = isset( $locale['decimal_point'] ) ? $locale['decimal_point'] : '.';
482 $decimal = ( ! empty( wc_get_price_decimal_separator() ) ) ? wc_get_price_decimal_separator() : $decimal_point;
483
484 $params = array(
485 /* translators: %s: decimal */
486 'i18n_decimal_error' => sprintf( __( 'Please enter a value with one decimal point (%s) without thousand separators.', 'woocommerce' ), $decimal ),
487 /* translators: %s: price decimal separator */
488 'i18n_mon_decimal_error' => sprintf( __( 'Please enter a value with one monetary decimal point (%s) without thousand separators and currency symbols.', 'woocommerce' ), wc_get_price_decimal_separator() ),
489 'i18n_country_iso_error' => __( 'Please enter in country code with two capital letters.', 'woocommerce' ),
490 'i18n_sale_less_than_regular_error' => __( 'Please enter in a value less than the regular price.', 'woocommerce' ),
491 'i18n_delete_product_notice' => __( 'This product has produced sales and may be linked to existing orders. Are you sure you want to delete it?', 'woocommerce' ),
492 'i18n_remove_personal_data_notice' => __( 'This action cannot be reversed. Are you sure you wish to erase personal data from the selected orders?', 'woocommerce' ),
493 'i18n_confirm_delete' => __( 'Are you sure you wish to delete this item?', 'woocommerce' ),
494 'i18n_global_unique_id_error' => __( 'Enter only numbers and hyphens (-). The letter X is allowed only as the final ISBN-10 check digit.', 'woocommerce' ),
495 'decimal_point' => $decimal,
496 'mon_decimal_point' => wc_get_price_decimal_separator(),
497 'ajax_url' => admin_url( 'admin-ajax.php' ),
498 'strings' => array(
499 'import_products' => __( 'Import', 'woocommerce' ),
500 'export_products' => __( 'Export', 'woocommerce' ),
501 // translators: %d: number of selected products.
502 'export_selected_products' => __( 'Export %d selected', 'woocommerce' ),
503 ),
504 'nonces' => array(
505 'gateway_toggle' => current_user_can( 'manage_woocommerce' ) ? wp_create_nonce( 'woocommerce-toggle-payment-gateway-enabled' ) : null,
506 'export_selected_products_nonce' => current_user_can( 'export' ) ? wp_create_nonce( 'export-selected-products' ) : null,
507 ),
508 'urls' => array(
509 'add_product' => \Automattic\WooCommerce\Utilities\FeaturesUtil::feature_is_enabled( 'product_block_editor' ) ? esc_url_raw( admin_url( 'admin.php?page=wc-admin&path=/add-product' ) ) : null,
510 'import_products' => current_user_can( 'import' ) ? esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_importer' ) ) : null,
511 'export_products' => current_user_can( 'export' ) ? esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_exporter' ) ) : null,
512 ),
513 );
514
515 wp_localize_script( 'woocommerce_admin', 'woocommerce_admin', $params );
516 }
517
518 // Edit product category pages.
519 if ( in_array( $screen_id, array( 'edit-product_cat' ) ) ) {
520 wp_enqueue_media();
521 }
522
523 // Products.
524 if ( in_array( $screen_id, array( 'edit-product' ) ) ) {
525 wp_enqueue_script( 'woocommerce_quick-edit', WC()->plugin_url() . '/assets/js/admin/quick-edit' . $suffix . '.js', array( 'jquery', 'woocommerce_admin' ), $version );
526
527 $params = array(
528 'strings' => array(
529 'allow_reviews' => esc_js( __( 'Enable reviews', 'woocommerce' ) ),
530 ),
531 );
532
533 wp_localize_script( 'woocommerce_quick-edit', 'woocommerce_quick_edit', $params );
534 }
535
536 // Product description.
537 if ( in_array( $screen_id, array( 'product' ), true ) ) {
538 wp_enqueue_script( 'wc-admin-product-editor', WC()->plugin_url() . '/assets/js/admin/product-editor' . $suffix . '.js', array( 'jquery' ), $version, false );
539
540 wp_localize_script(
541 'wc-admin-product-editor',
542 'woocommerce_admin_product_editor',
543 array(
544 'i18n_description' => esc_js( __( 'Product description', 'woocommerce' ) ),
545 )
546 );
547 }
548
549 // Meta boxes.
550 /* phpcs:disable */
551 if ( in_array( $screen_id, array( 'product', 'edit-product' ) ) ) {
552 wp_enqueue_media();
553 wp_register_script( 'wc-admin-product-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-product' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'media-models', 'underscore' ), $version );
554 wp_register_script( 'wc-admin-variation-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-product-variation' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'wc-serializejson', 'media-models', 'backbone', 'jquery-ui-sortable', 'wc-backbone-modal', 'wp-data', 'wp-notices' ), $version );
555
556 wp_enqueue_script( 'wc-admin-product-meta-boxes' );
557 wp_enqueue_script( 'wc-admin-variation-meta-boxes' );
558
559 $params = array(
560 'post_id' => isset( $post->ID ) ? $post->ID : '',
561 'plugin_url' => WC()->plugin_url(),
562 'ajax_url' => admin_url( 'admin-ajax.php' ),
563 'woocommerce_placeholder_img_src' => wc_placeholder_img_src(),
564 'add_variation_nonce' => wp_create_nonce( 'add-variation' ),
565 'link_variation_nonce' => wp_create_nonce( 'link-variations' ),
566 'delete_variations_nonce' => wp_create_nonce( 'delete-variations' ),
567 'load_variations_nonce' => wp_create_nonce( 'load-variations' ),
568 'save_variations_nonce' => wp_create_nonce( 'save-variations' ),
569 'bulk_edit_variations_nonce' => wp_create_nonce( 'bulk-edit-variations' ),
570 /* translators: %d: Number of variations */
571 'i18n_link_all_variations' => esc_js( sprintf( __( 'Do you want to generate all variations? This will create a new variation for each and every possible combination of variation attributes (max %d per run).', 'woocommerce' ), Constants::is_defined( 'WC_MAX_LINKED_VARIATIONS' ) ? Constants::get_constant( 'WC_MAX_LINKED_VARIATIONS' ) : 50 ) ),
572 'i18n_enter_a_value' => esc_js( __( 'Enter a value', 'woocommerce' ) ),
573 'i18n_enter_menu_order' => esc_js( __( 'Variation menu order (determines position in the list of variations)', 'woocommerce' ) ),
574 'i18n_enter_a_value_fixed_or_percent' => esc_js( __( 'Enter a value (fixed or %)', 'woocommerce' ) ),
575 'i18n_sale_price_warning' => esc_js( __( 'Warning: Sale prices will be removed if they are not lower than regular prices.', 'woocommerce' ) ),
576 'i18n_delete_all_variations' => esc_js( __( 'Are you sure you want to delete all variations? This cannot be undone.', 'woocommerce' ) ),
577 'i18n_last_warning' => esc_js( __( 'Last warning, are you sure?', 'woocommerce' ) ),
578 'i18n_choose_image' => esc_js( __( 'Choose an image', 'woocommerce' ) ),
579 'i18n_set_image' => esc_js( __( 'Set variation image', 'woocommerce' ) ),
580 'i18n_variation_added' => esc_js( __( '1 variation added', 'woocommerce' ) ),
581 'i18n_variations_added' => esc_js( __( '%qty% variations added', 'woocommerce' ) ),
582 'i18n_remove_variation' => esc_js( __( 'Are you sure you want to remove this variation?', 'woocommerce' ) ),
583 'i18n_scheduled_sale_start' => esc_js( __( 'Sale start date (YYYY-MM-DD format or leave blank)', 'woocommerce' ) ),
584 'i18n_scheduled_sale_end' => esc_js( __( 'Sale end date (YYYY-MM-DD format or leave blank)', 'woocommerce' ) ),
585 'i18n_edited_variations' => esc_js( __( 'Save changes before changing page?', 'woocommerce' ) ),
586 'i18n_variation_count_single' => esc_js( __( '1 variation', 'woocommerce' ) ),
587 'i18n_variation_count_plural' => esc_js( __( '%qty% variations', 'woocommerce' ) ),
588 'i18n_variation_cost_remove_warning' => esc_js( __( 'The custom cost of goods sold values will revert back to their defaults for all the variations. Would you like to continue?', 'woocommerce' ) ),
589 'variations_per_page' => absint( apply_filters( 'woocommerce_admin_meta_boxes_variations_per_page', 15 ) ),
590 );
591
592 wp_localize_script( 'wc-admin-variation-meta-boxes', 'woocommerce_admin_meta_boxes_variations', $params );
593 }
594 /* phpcs: enable */
595 if ( $this->is_order_meta_box_screen( $screen_id ) ) {
596 $default_location = wc_get_customer_default_location();
597
598 wp_enqueue_script( 'wc-admin-order-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-order' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'wc-backbone-modal', 'selectWoo', 'wc-clipboard', 'wp-a11y' ), $version );
599 wp_localize_script(
600 'wc-admin-order-meta-boxes',
601 'woocommerce_admin_meta_boxes_order',
602 array(
603 'countries' => wp_json_encode(
604 array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ),
605 JSON_HEX_TAG | JSON_UNESCAPED_SLASHES
606 ),
607 'i18n_select_state_text' => esc_attr__( 'Select an option&hellip;', 'woocommerce' ),
608 'default_country' => isset( $default_location['country'] ) ? $default_location['country'] : '',
609 'default_state' => isset( $default_location['state'] ) ? $default_location['state'] : '',
610 'placeholder_name' => esc_attr__( 'Name (required)', 'woocommerce' ),
611 'placeholder_value' => esc_attr__( 'Value (required)', 'woocommerce' ),
612 )
613 );
614 }
615 /* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */
616 if ( in_array( $screen_id, array( 'shop_coupon', 'edit-shop_coupon' ) ) ) {
617 wp_enqueue_script( 'wc-admin-coupon-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-coupon' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), $version );
618 wp_localize_script(
619 'wc-admin-coupon-meta-boxes',
620 'woocommerce_admin_meta_boxes_coupon',
621 array(
622 'generate_button_text' => esc_html__( 'Generate coupon code', 'woocommerce' ),
623 'characters' => apply_filters( 'woocommerce_coupon_code_generator_characters', 'ABCDEFGHJKMNPQRSTUVWXYZ23456789' ),
624 'char_length' => apply_filters( 'woocommerce_coupon_code_generator_character_length', 8 ),
625 'prefix' => apply_filters( 'woocommerce_coupon_code_generator_prefix', '' ),
626 'suffix' => apply_filters( 'woocommerce_coupon_code_generator_suffix', '' ),
627 )
628 );
629 }
630 /* phpcs: enable */
631 if ( in_array( str_replace( 'edit-', '', $screen_id ), array( 'shop_coupon', 'product' ), true ) || $this->is_order_meta_box_screen( $screen_id ) ) {
632 $post_id = isset( $post->ID ) ? $post->ID : '';
633 $currency = '';
634 $remove_item_notice = __( 'Are you sure you want to remove the selected items?', 'woocommerce' );
635 $remove_fee_notice = __( 'Are you sure you want to remove the selected fees?', 'woocommerce' );
636 $remove_shipping_notice = __( 'Are you sure you want to remove the selected shipping?', 'woocommerce' );
637
638 // Eventually this will become wc_data_or_post object as we implement more custom tables.
639 $order_or_post_object = $post;
640 if ( ( $theorder instanceof WC_Order ) && $this->is_order_meta_box_screen( $screen_id ) ) {
641 $order_or_post_object = $theorder;
642 if ( $order_or_post_object ) {
643 $currency = $order_or_post_object->get_currency();
644
645 if ( ! $order_or_post_object->has_status( array( OrderStatus::PENDING, OrderStatus::FAILED, OrderStatus::CANCELLED ) ) ) {
646 $remove_item_notice = $remove_item_notice . ' ' . __( "You may need to manually restore the item's stock.", 'woocommerce' );
647 }
648 }
649 }
650
651 $params = array(
652 'remove_item_notice' => $remove_item_notice,
653 'remove_fee_notice' => $remove_fee_notice,
654 'remove_shipping_notice' => $remove_shipping_notice,
655 'i18n_select_items' => __( 'Please select some items.', 'woocommerce' ),
656 'i18n_do_refund' => __( 'Are you sure you wish to process this refund? This action cannot be undone.', 'woocommerce' ),
657 'i18n_delete_refund' => __( 'Are you sure you wish to delete this refund? This action cannot be undone.', 'woocommerce' ),
658 'i18n_delete_tax' => __( 'Are you sure you wish to delete this tax column? This action cannot be undone.', 'woocommerce' ),
659 'remove_item_meta' => __( 'Remove this item meta?', 'woocommerce' ),
660 'name_label' => __( 'Name', 'woocommerce' ),
661 'remove_label' => __( 'Remove', 'woocommerce' ),
662 'click_to_toggle' => __( 'Click to toggle', 'woocommerce' ),
663 'values_label' => __( 'Value(s)', 'woocommerce' ),
664 'text_attribute_tip' => __( 'Enter some text, or some attributes by pipe (|) separating values.', 'woocommerce' ),
665 'visible_label' => __( 'Visible on the product page', 'woocommerce' ),
666 'used_for_variations_label' => __( 'Used for variations', 'woocommerce' ),
667 'new_attribute_prompt' => __( 'Enter a name for the new attribute term:', 'woocommerce' ),
668 'calc_totals' => __( 'Recalculate totals? This will calculate taxes based on the customers country (or the store base country) and update totals.', 'woocommerce' ),
669 'copy_billing' => __( 'Copy billing information to shipping information? This will remove any currently entered shipping information.', 'woocommerce' ),
670 'load_billing' => __( "Load the customer's billing information? This will remove any currently entered billing information.", 'woocommerce' ),
671 'load_shipping' => __( "Load the customer's shipping information? This will remove any currently entered shipping information.", 'woocommerce' ),
672 'featured_label' => __( 'Featured', 'woocommerce' ),
673 'prices_include_tax' => esc_attr( get_option( 'woocommerce_prices_include_tax' ) ),
674 'tax_based_on' => esc_attr( get_option( 'woocommerce_tax_based_on' ) ),
675 'round_at_subtotal' => esc_attr( get_option( 'woocommerce_tax_round_at_subtotal' ) ),
676 'no_customer_selected' => __( 'No customer selected', 'woocommerce' ),
677 'plugin_url' => WC()->plugin_url(),
678 'ajax_url' => admin_url( 'admin-ajax.php' ),
679 'order_item_nonce' => wp_create_nonce( 'order-item' ),
680 'add_attribute_nonce' => wp_create_nonce( 'add-attribute' ),
681 'save_attributes_nonce' => wp_create_nonce( 'save-attributes' ),
682 'add_attributes_and_variations' => wp_create_nonce( 'add-attributes-and-variations' ),
683 'calc_totals_nonce' => wp_create_nonce( 'calc-totals' ),
684 'get_customer_details_nonce' => wp_create_nonce( 'get-customer-details' ),
685 'search_products_nonce' => wp_create_nonce( 'search-products' ),
686 'grant_access_nonce' => wp_create_nonce( 'grant-access' ),
687 'revoke_access_nonce' => wp_create_nonce( 'revoke-access' ),
688 'add_order_note_nonce' => wp_create_nonce( 'add-order-note' ),
689 'delete_order_note_nonce' => wp_create_nonce( 'delete-order-note' ),
690 'calendar_image' => WC()->plugin_url() . '/assets/images/calendar.png',
691 'post_id' => $this->is_order_meta_box_screen( $screen_id ) && isset( $order_or_post_object ) ? \Automattic\WooCommerce\Utilities\OrderUtil::get_post_or_order_id( $order_or_post_object ) : $post_id,
692 'base_country' => WC()->countries->get_base_country(),
693 'currency_format_num_decimals' => wc_get_price_decimals(),
694 'currency_format_symbol' => get_woocommerce_currency_symbol( $currency ),
695 'currency_format_decimal_sep' => esc_attr( wc_get_price_decimal_separator() ),
696 'currency_format_thousand_sep' => esc_attr( wc_get_price_thousand_separator() ),
697 'currency_format' => esc_attr( str_replace( array( '%1$s', '%2$s' ), array( '%s', '%v' ), get_woocommerce_price_format() ) ), // For accounting JS.
698 'rounding_precision' => wc_get_rounding_precision(),
699 'tax_rounding_mode' => wc_get_tax_rounding_mode(),
700 'product_types' => array_unique( array_merge( array( ProductType::SIMPLE, ProductType::GROUPED, ProductType::VARIABLE, ProductType::EXTERNAL ), array_keys( wc_get_product_types() ) ) ),
701 'i18n_download_permission_fail' => __( 'Could not grant access - the user may already have permission for this file or billing email is not set. Ensure the billing email is set, and the order has been saved.', 'woocommerce' ),
702 'i18n_permission_revoke' => __( 'Are you sure you want to revoke access to this download?', 'woocommerce' ),
703 'i18n_tax_rate_already_exists' => __( 'You cannot add the same tax rate twice!', 'woocommerce' ),
704 'i18n_delete_note' => __( 'Are you sure you wish to delete this note? This action cannot be undone.', 'woocommerce' ),
705 'i18n_delete_customer_note' => __( 'Are you sure you wish to delete this note? This action cannot be undone. Caution: This only removes the note from your records — it does not recall the email already sent to the customer.', 'woocommerce' ),
706 'i18n_no_notes_yet' => __( 'There are no notes yet.', 'woocommerce' ),
707 'i18n_order_note_added' => __( 'Order note added.', 'woocommerce' ),
708 'i18n_customer_order_note_added' => __( 'Order note added and emailed to the customer.', 'woocommerce' ),
709 'i18n_apply_coupon' => __( 'Enter a coupon code to apply. Discounts are applied to line totals, before taxes.', 'woocommerce' ),
710 'i18n_add_fee' => __( 'Enter a fixed amount or percentage to apply as a fee.', 'woocommerce' ),
711 'i18n_attribute_name_placeholder' => __( 'New attribute', 'woocommerce' ),
712 'i18n_product_simple_tip' => __( '<b>Simple –</b> covers the vast majority of any products you may sell. Simple products are shipped and have no options. For example, a book.', 'woocommerce' ),
713 'i18n_product_grouped_tip' => __( '<b>Grouped –</b> a collection of related products that can be purchased individually and only consist of simple products. For example, a set of six drinking glasses.', 'woocommerce' ),
714 'i18n_product_external_tip' => __( '<b>External or Affiliate –</b> one that you list and describe on your website but is sold elsewhere.', 'woocommerce' ),
715 'i18n_product_variable_tip' => __( '<b>Variable –</b> a product with variations, each of which may have a different SKU, price, stock option, etc. For example, a t-shirt available in different colors and/or sizes.', 'woocommerce' ),
716 'i18n_product_other_tip' => __( 'Product types define available product details and attributes, such as downloadable files and variations. They’re also used for analytics and inventory management.', 'woocommerce' ),
717 'i18n_product_description_tip' => __( 'Describe this product. What makes it unique? What are its most important features?', 'woocommerce' ),
718 'i18n_product_short_description_tip' => __( 'Summarize this product in 1-2 short sentences. We’ll show it at the top of the page.', 'woocommerce' ),
719 'i18n_save_attribute_variation_tip' => __( 'Make sure you enter the name and values for each attribute.', 'woocommerce' ),
720 /* translators: %1$s: maximum file size */
721 'i18n_product_image_tip' => sprintf( __( 'For best results, upload JPEG or PNG files that are 1000 by 1000 pixels or larger. Maximum upload file size: %1$s.', 'woocommerce' ), size_format( wp_max_upload_size() ) ),
722 'i18n_remove_used_attribute_confirmation_message' => __( 'If you remove this attribute, customers will no longer be able to purchase some variations of this product.', 'woocommerce' ),
723 'i18n_add_attribute_error_notice' => __( 'Adding new attribute failed.', 'woocommerce' ),
724 /* translators: %s: WC_DELIMITER */
725 'i18n_attributes_default_placeholder' => sprintf( esc_attr__( 'Enter some descriptive text. Use “%s” to separate different values.', 'woocommerce' ), esc_attr( WC_DELIMITER ) ),
726 'i18n_attributes_used_for_variations_placeholder' => sprintf( esc_attr__( 'Enter options for customers to choose from, f.e. “Blue” or “Large”. Use “%s” to separate different options.', 'woocommerce' ), esc_attr( WC_DELIMITER ) )
727 );
728
729 $cogs_controller = wc_get_container()->get( CostOfGoodsSoldController::class );
730 if( $cogs_controller->feature_is_enabled() ) {
731 $params['cogs_value_tooltip_simple_products'] = esc_attr( $cogs_controller->get_general_cost_edit_field_tooltip( false ) );
732 $params['cogs_value_tooltip_variable_products'] = esc_attr( $cogs_controller->get_general_cost_edit_field_tooltip( true ) );
733 }
734 wp_localize_script( 'wc-admin-meta-boxes', 'woocommerce_admin_meta_boxes', $params );
735 }
736
737 // Term ordering - only when sorting by term_order.
738 /* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */
739 if ( ( strstr( $screen_id, 'edit-pa_' ) || ( ! empty( $_GET['taxonomy'] ) && in_array( wp_unslash( $_GET['taxonomy'] ), apply_filters( 'woocommerce_sortable_taxonomies', array( 'product_cat' ) ) ) ) ) && ! isset( $_GET['orderby'] ) ) {
740
741 wp_register_script( 'woocommerce_term_ordering', WC()->plugin_url() . '/assets/js/admin/term-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), $version );
742 wp_enqueue_script( 'woocommerce_term_ordering' );
743
744 $taxonomy = isset( $_GET['taxonomy'] ) ? wc_clean( wp_unslash( $_GET['taxonomy'] ) ) : '';
745
746 $woocommerce_term_order_params = array(
747 'taxonomy' => $taxonomy,
748 'nonce' => wp_create_nonce( 'term-ordering' ),
749 );
750
751 wp_localize_script( 'woocommerce_term_ordering', 'woocommerce_term_ordering_params', $woocommerce_term_order_params );
752 }
753 /* phpcs: enable */
754
755 // Product sorting - only when sorting by menu order on the products page.
756 if ( current_user_can( 'edit_others_pages' ) && 'edit-product' === $screen_id && isset( $wp_query->query['orderby'] ) && 'menu_order title' === $wp_query->query['orderby'] ) {
757 wp_register_script( 'woocommerce_product_ordering', WC()->plugin_url() . '/assets/js/admin/product-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), $version, true );
758 wp_enqueue_script( 'woocommerce_product_ordering' );
759
760 wp_localize_script(
761 'woocommerce_product_ordering',
762 'woocommerce_product_ordering_params',
763 array( 'nonce' => wp_create_nonce( 'product-ordering' ) )
764 );
765 }
766
767 // Reports Pages.
768 /* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */
769 if ( in_array( $screen_id, apply_filters( 'woocommerce_reports_screen_ids', array( $wc_screen_id . '_page_wc-reports', 'toplevel_page_wc-reports' ) ) ) ) {
770 wp_register_script( 'wc-reports', WC()->plugin_url() . '/assets/js/admin/reports' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker' ), $version );
771
772 wp_enqueue_script( 'wc-reports' );
773 wp_enqueue_script( 'wc-flot' );
774 wp_enqueue_script( 'wc-flot-resize' );
775 wp_enqueue_script( 'wc-flot-time' );
776 wp_enqueue_script( 'wc-flot-pie' );
777 wp_enqueue_script( 'wc-flot-stack' );
778 }
779 /* phpcs: enable */
780
781 // API settings.
782 if ( $wc_screen_id . '_page_wc-settings' === $screen_id && isset( $_GET['section'] ) && 'keys' == $_GET['section'] ) {
783 wp_register_script( 'wc-api-keys', WC()->plugin_url() . '/assets/js/admin/api-keys' . $suffix . '.js', array( 'jquery', 'woocommerce_admin', 'underscore', 'backbone', 'wp-util', 'wc-qrcode', 'wc-clipboard' ), $version, true );
784 wp_enqueue_script( 'wc-api-keys' );
785 wp_localize_script(
786 'wc-api-keys',
787 'woocommerce_admin_api_keys',
788 array(
789 'ajax_url' => admin_url( 'admin-ajax.php' ),
790 'update_api_nonce' => wp_create_nonce( 'update-api-key' ),
791 'clipboard_failed' => esc_html__( 'Copying to clipboard failed. Please press Ctrl/Cmd+C to copy.', 'woocommerce' ),
792 )
793 );
794 }
795
796 // Email settings.
797 if ( $wc_screen_id . '_page_wc-settings' === $screen_id && isset( $_GET['tab'] ) && 'email' === $_GET['tab'] ) {
798 wp_enqueue_media();
799 }
800
801 // System status.
802 if ( $wc_screen_id . '_page_wc-status' === $screen_id ) {
803 wp_register_script( 'wc-admin-system-status', WC()->plugin_url() . '/assets/js/admin/system-status' . $suffix . '.js', array( 'wc-clipboard' ), $version );
804 wp_enqueue_script( 'wc-admin-system-status' );
805 wp_localize_script(
806 'wc-admin-system-status',
807 'woocommerce_admin_system_status',
808 array(
809 'delete_log_confirmation' => esc_js( __( 'Are you sure you want to delete this log?', 'woocommerce' ) ),
810 'run_tool_confirmation' => esc_js( __( 'Are you sure you want to run this tool?', 'woocommerce' ) ),
811 )
812 );
813 }
814
815 if ( in_array( $screen_id, array( 'user-edit', 'profile' ) ) ) {
816 wp_register_script( 'wc-users', WC()->plugin_url() . '/assets/js/admin/users' . $suffix . '.js', array( 'jquery', 'wc-enhanced-select', 'selectWoo' ), $version, true );
817 wp_enqueue_script( 'wc-users' );
818 wp_localize_script(
819 'wc-users',
820 'wc_users_params',
821 array(
822 'countries' => wp_json_encode(
823 array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ),
824 JSON_HEX_TAG | JSON_UNESCAPED_SLASHES
825 ),
826 'i18n_select_state_text' => esc_attr__( 'Select an option&hellip;', 'woocommerce' ),
827 )
828 );
829 }
830
831 if ( WC_Marketplace_Suggestions::show_suggestions_for_screen( $screen_id ) ) {
832 $active_plugin_slugs = array_map( 'dirname', get_option( 'active_plugins' ) );
833 wp_register_script(
834 'marketplace-suggestions',
835 WC()->plugin_url() . '/assets/js/admin/marketplace-suggestions' . $suffix . '.js',
836 array( 'jquery', 'underscore', 'wc-js-cookie' ),
837 $version,
838 true
839 );
840 wp_localize_script(
841 'marketplace-suggestions',
842 'marketplace_suggestions',
843 array(
844 'dismiss_suggestion_nonce' => wp_create_nonce( 'add_dismissed_marketplace_suggestion' ),
845 'active_plugins' => $active_plugin_slugs,
846 'dismissed_suggestions' => WC_Marketplace_Suggestions::get_dismissed_suggestions(),
847 'suggestions_data' => WC_Marketplace_Suggestions::get_suggestions_api_data(),
848 'manage_suggestions_url' => admin_url( 'admin.php?page=wc-settings&tab=advanced&section=woocommerce_com' ),
849 'in_app_purchase_params' => WC_Admin_Addons::get_in_app_purchase_url_params(),
850 'admin_base_url' => admin_url(),
851 'i18n_marketplace_suggestions_default_cta'
852 => esc_html__( 'Learn More', 'woocommerce' ),
853 'i18n_marketplace_suggestions_dismiss_tooltip'
854 => esc_attr__( 'Dismiss this suggestion', 'woocommerce' ),
855 'i18n_marketplace_suggestions_manage_suggestions'
856 => esc_html__( 'Manage suggestions', 'woocommerce' ),
857 )
858 );
859 wp_enqueue_script( 'marketplace-suggestions' );
860 }
861
862 // Marketplace promotions.
863 if ( in_array( $screen_id, array( 'edit-shop_coupon', 'woocommerce_page_wc-admin' ), true ) ) {
864
865 $promotions = WC_Admin_Marketplace_Promotions::get_active_promotions();
866
867 if ( false === $promotions ) {
868 return;
869 }
870
871 wp_add_inline_script(
872 'wc-admin-app',
873 'window.wcMarketplace = ' . wp_json_encode( array( 'promotions' => $promotions ), JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
874 'before'
875 );
876 }
877 }
878
879 /**
880 * Enqueue a script in WordPress admin.
881 * Similar to `WCAdminAssets::register_script()` but without enqueuing unnecessary dependencies.
882 *
883 * @return void
884 */
885 private function enqueue_script( string $script_path_name, string $script_name ) {
886 $script_assets_filename = WCAdminAssets::get_script_asset_filename( $script_path_name, $script_name );
887 $script_assets = require WC_ADMIN_ABSPATH . WC_ADMIN_DIST_JS_FOLDER . $script_path_name . '/' . $script_assets_filename;
888
889 wp_enqueue_script(
890 'wc-admin-' . $script_name,
891 WCAdminAssets::get_url( $script_path_name . '/' . $script_name, 'js' ),
892 $script_assets['dependencies'],
893 WCAdminAssets::get_file_version( 'js', $script_assets['version'] ),
894 true
895 );
896 }
897
898 /**
899 * Enqueue command palette assets.
900 *
901 * @return void
902 */
903 public function enqueue_command_palette_assets() {
904 $this->enqueue_script( 'wp-admin-scripts', 'command-palette' );
905
906 $admin_features_disabled = apply_filters( 'woocommerce_admin_disabled', false );
907 if ( ! $admin_features_disabled ) {
908 $analytics_reports = Analytics::get_report_pages();
909 if ( is_array( $analytics_reports ) && count( $analytics_reports ) > 0 ) {
910 $formatted_analytics_reports = array_map( function( $report ) {
911 if ( ! is_array( $report ) ) {
912 return null;
913 }
914 $title = array_key_exists( 'title', $report ) ? $report['title'] : '';
915 $path = array_key_exists( 'path', $report ) ? $report['path'] : '';
916 if (
917 is_string( $title ) && $title !== "" &&
918 is_string( $path ) && $path !== ""
919 ) {
920 return array(
921 'title' => wp_strip_all_tags( $title ),
922 'path' => $path,
923 );
924 }
925 return null;
926 }, $analytics_reports );
927 $formatted_analytics_reports = array_filter( $formatted_analytics_reports, 'is_array' );
928
929 $this->enqueue_script( 'wp-admin-scripts', 'command-palette-analytics' );
930 wp_localize_script(
931 'wc-admin-command-palette-analytics',
932 'wcCommandPaletteAnalytics',
933 array(
934 'reports' => $formatted_analytics_reports,
935 )
936 );
937 }
938 }
939 }
940
941 /**
942 * Helper function to determine whether the current screen is an order edit screen.
943 *
944 * @param string $screen_id Screen ID.
945 *
946 * @return bool Whether the current screen is an order edit screen.
947 */
948 private function is_order_meta_box_screen( $screen_id ) {
949 $screen_id = str_replace( 'edit-', '', $screen_id );
950
951 $types_with_metaboxes_screen_ids = array_filter(
952 array_map(
953 'wc_get_page_screen_id',
954 wc_get_order_types( 'order-meta-boxes' )
955 )
956 );
957
958 return in_array( $screen_id, $types_with_metaboxes_screen_ids, true );
959 }
960
961 }
962
963 endif;
964
965 return new WC_Admin_Assets();
966