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-beta.1 10.0.2 5.2.0-rc.1 10.0.3 5.2.0-rc.2 10.0.4 5.2.1 10.0.5 5.2.2 10.0.6 5.2.3 10.1.0 5.2.4 10.1.0-rc.1 5.2.5 10.1.0-rc.2 5.3.0 10.1.0-rc.3 5.3.0-beta.1 10.1.0-rc.4 5.3.0-rc.1 10.1.1 5.3.0-rc.2 10.1.2 5.3.1 10.1.3 5.3.2 10.1.4 5.3.3 10.2.0 5.4.0 10.2.0-beta.1 5.4.0-beta.1 10.2.0-beta.2 5.4.0-rc.1 10.2.0-rc.1 5.4.1 10.2.1 5.4.2 10.2.2 5.4.3 10.2.3 5.4.4 10.2.4 5.4.5 10.3.0 5.5.0 10.3.0-beta.1 5.5.0-beta.1 10.3.0-beta.2 5.5.0-rc.1 10.3.0-rc.1 5.5.0-rc.2 10.3.0-rc.2 5.5.1 10.3.1 5.5.2 10.3.2 5.5.3 10.3.3 5.5.4 10.3.4 5.5.5 10.3.5 5.6.0 10.3.6 5.6.0-beta.1 10.3.7 5.6.0-rc.1 10.3.8 5.6.0-rc.2 10.4.0 5.6.1 10.4.0-beta.1 5.6.2 10.4.0-beta.2 5.6.3 10.4.0-rc.1 5.7.0 10.4.1 5.7.0-beta.1 10.4.2 5.7.0-rc.1 10.4.3 5.7.1 10.4.4 5.7.2 10.5.0 5.7.3 10.5.0-beta.1 5.8.0 10.5.0-beta.2 5.8.0-beta.1 10.5.0-rc.1 5.8.0-beta.2 10.5.0-rc.2 5.8.0-rc.1 10.5.0-rc.3 5.8.1 10.5.1 5.8.2 10.5.2 5.9.0 10.5.3 5.9.0-beta.1 10.6.0 5.9.0-rc.1 10.6.0-beta.1 5.9.0-rc.2 10.6.0-beta.2 5.9.1 10.6.0-rc.1 5.9.2 10.6.1 6.0.0 10.6.2 6.0.0-beta.1 10.7.0 6.0.0-rc.1 10.7.0-beta.1 6.0.1 10.7.0-beta.2 6.0.2 10.7.0-rc.1 6.1.0 3.0.0 6.1.0-beta.1 3.0.1 6.1.0-rc.1 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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 3 weeks ago importers 1 month ago list-tables 1 month ago marketplace-suggestions 1 year ago meta-boxes 1 month ago notes 3 months ago plugin-updates 2 years ago reports 1 month ago settings 1 month ago views 1 month ago class-wc-admin-addons.php 10 months ago class-wc-admin-api-keys-table-list.php 3 years ago class-wc-admin-api-keys.php 1 month ago class-wc-admin-assets.php 1 month ago class-wc-admin-attributes.php 1 month ago class-wc-admin-brands.php 1 month ago class-wc-admin-customize.php 6 years ago class-wc-admin-dashboard-setup.php 1 month ago class-wc-admin-dashboard.php 1 month ago class-wc-admin-duplicate-product.php 1 month ago class-wc-admin-exporters.php 1 year ago class-wc-admin-help.php 2 years ago class-wc-admin-importers.php 1 year ago class-wc-admin-log-table-list.php 6 months ago class-wc-admin-marketplace-promotions.php 1 month ago class-wc-admin-menus.php 1 month ago class-wc-admin-meta-boxes.php 2 months 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 month ago class-wc-admin-profile.php 1 year ago class-wc-admin-reports.php 6 months ago class-wc-admin-settings.php 1 month ago class-wc-admin-setup-wizard.php 2 months ago class-wc-admin-status.php 1 year ago class-wc-admin-taxonomies.php 2 months ago class-wc-admin-upload-downloadable-product.php 2 years ago class-wc-admin-webhooks-table-list.php 2 months ago class-wc-admin-webhooks.php 1 month ago class-wc-admin.php 5 months ago wc-admin-functions.php 1 month 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 * Whether the current screen should get the #wc-lost-connection-notice markup and toggle handler.
46 * Limited to Woo admin screens, minus wc-admin React pages and classic post edit screens, which get WP
47 * core's own notice. Classic order edit is the exception: core's notice there wrongly claims local
48 * autosave backups are running, which disable_autosave() has turned off.
49 *
50 * @return bool Whether to render and toggle the notice.
51 */
52 private function should_show_lost_connection_notice() {
53 $screen = get_current_screen();
54
55 if ( ! $screen || ! in_array( $screen->id, wc_get_screen_ids(), true ) ) {
56 return false;
57 }
58
59 $is_wc_admin_page = class_exists( '\Automattic\WooCommerce\Admin\PageController' )
60 && \Automattic\WooCommerce\Admin\PageController::is_admin_page();
61 if ( $is_wc_admin_page ) {
62 return false;
63 }
64
65 $is_classic_order_edit_screen = 'post' === $screen->base
66 && in_array( $screen->post_type, wc_get_order_types( 'order-meta-boxes' ), true );
67
68 return 'post' !== $screen->base || $is_classic_order_edit_screen;
69 }
70
71 /**
72 * Render a #wc-lost-connection-notice mirroring WP core's own notice on post edit screens.
73 * See should_show_lost_connection_notice() for which screens get it.
74 *
75 * @return void
76 */
77 public function render_lost_connection_notice() {
78 if ( ! $this->should_show_lost_connection_notice() ) {
79 return;
80 }
81 ?>
82 <div id="wc-lost-connection-notice" class="notice error hidden">
83 <p>
84 <span class="spinner"></span>
85 <strong><?php esc_html_e( 'Connection lost.' ); /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- Reusing WP core translation. */ ?></strong>
86 <?php esc_html_e( 'Saving has been disabled until you are reconnected.' ); /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- Reusing WP core translation. */ ?>
87 </p>
88 </div>
89 <?php
90 }
91
92 /**
93 * Enqueue styles.
94 */
95 public function admin_styles() {
96 $version = Constants::get_constant( 'WC_VERSION' );
97 $screen = get_current_screen();
98 $screen_id = $screen ? $screen->id : '';
99
100 // Register admin styles.
101 wp_register_style( 'woocommerce_admin_menu_styles', WC()->plugin_url() . '/assets/css/menu.css', array(), $version );
102 wp_register_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), $version );
103 wp_register_style( 'jquery-ui-style', WC()->plugin_url() . '/assets/css/jquery-ui/jquery-ui.min.css', array(), $version );
104 wp_register_style( 'woocommerce_admin_dashboard_styles', WC()->plugin_url() . '/assets/css/dashboard.css', array(), $version );
105 wp_register_style( 'woocommerce_admin_print_reports_styles', WC()->plugin_url() . '/assets/css/reports-print.css', array(), $version, 'print' );
106 wp_register_style( 'woocommerce_admin_marketplace_styles', WC()->plugin_url() . '/assets/css/marketplace-suggestions.css', array(), $version );
107 wp_register_style( 'woocommerce_admin_privacy_styles', WC()->plugin_url() . '/assets/css/privacy.css', array(), $version );
108
109 // Add RTL support for admin styles.
110 wp_style_add_data( 'woocommerce_admin_menu_styles', 'rtl', 'replace' );
111 wp_style_add_data( 'woocommerce_admin_styles', 'rtl', 'replace' );
112 wp_style_add_data( 'woocommerce_admin_dashboard_styles', 'rtl', 'replace' );
113 wp_style_add_data( 'woocommerce_admin_print_reports_styles', 'rtl', 'replace' );
114 wp_style_add_data( 'woocommerce_admin_marketplace_styles', 'rtl', 'replace' );
115 wp_style_add_data( 'woocommerce_admin_privacy_styles', 'rtl', 'replace' );
116
117 if ( $screen && $screen->is_block_editor() ) {
118 if ( ! wp_is_block_theme() ) {
119 wp_register_style( 'woocommerce-classictheme-editor-fonts', WC()->plugin_url() . '/assets/css/woocommerce-classictheme-editor-fonts.css', array(), $version );
120 wp_enqueue_style( 'woocommerce-classictheme-editor-fonts' );
121 }
122
123 $styles = WC_Frontend_Scripts::get_styles();
124
125 if ( $styles ) {
126 foreach ( $styles as $handle => $args ) {
127 wp_register_style(
128 $handle,
129 $args['src'],
130 $args['deps'],
131 $args['version'],
132 $args['media']
133 );
134
135 if ( ! isset( $args['has_rtl'] ) ) {
136 wp_style_add_data( $handle, 'rtl', 'replace' );
137 }
138
139 wp_enqueue_style( $handle );
140 }
141 }
142 }
143
144 // Sitewide menu CSS.
145 wp_enqueue_style( 'woocommerce_admin_menu_styles' );
146
147 // Admin styles for WC pages only.
148 if ( in_array( $screen_id, wc_get_screen_ids() ) ) {
149 wp_enqueue_style( 'woocommerce_admin_styles' );
150 wp_enqueue_style( 'jquery-ui-style' );
151 wp_enqueue_style( 'wp-color-picker' );
152 }
153
154 if ( in_array( $screen_id, array( 'dashboard' ) ) ) {
155 wp_enqueue_style( 'woocommerce_admin_dashboard_styles' );
156 }
157
158 if ( in_array( $screen_id, array( 'woocommerce_page_wc-reports', 'toplevel_page_wc-reports' ) ) ) {
159 wp_enqueue_style( 'woocommerce_admin_print_reports_styles' );
160 }
161
162 // Privacy Policy Guide css for back-compat.
163 if ( isset( $_GET['wp-privacy-policy-guide'] ) || in_array( $screen_id, array( 'privacy-policy-guide' ) ) ) {
164 wp_enqueue_style( 'woocommerce_admin_privacy_styles' );
165 }
166
167 // @deprecated 2.3.
168 if ( has_action( 'woocommerce_admin_css' ) ) {
169 /* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */
170 do_action( 'woocommerce_admin_css' );
171 /* phpcs: enable */
172 wc_deprecated_function( 'The woocommerce_admin_css action', '2.3', 'admin_enqueue_scripts' );
173 }
174
175 if ( WC_Marketplace_Suggestions::show_suggestions_for_screen( $screen_id ) ) {
176 wp_enqueue_style( 'woocommerce_admin_marketplace_styles' );
177 }
178 }
179
180 /**
181 * Get the scripts used for registration.
182 *
183 * @return array
184 */
185 private function get_scripts(): array {
186 $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min';
187 $version = Constants::get_constant( 'WC_VERSION' );
188 $plugin_url = WC()->plugin_url();
189
190 return array(
191 array(
192 'handle' => 'woocommerce_admin',
193 'path' => $plugin_url . '/assets/js/admin/woocommerce_admin' . $suffix . '.js',
194 'dependencies' => array( 'jquery', 'wc-jquery-blockui', 'jquery-ui-sortable', 'jquery-ui-widget', 'jquery-ui-core', 'wc-jquery-tiptip' ),
195 'version' => $version,
196 ),
197 array(
198 'legacy_handle' => 'jquery-blockui',
199 'handle' => 'wc-jquery-blockui',
200 'path' => $plugin_url . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js',
201 'dependencies' => array( 'jquery' ),
202 'version' => '2.70',
203 'args' => array(
204 'in_footer' => true,
205 ),
206 ),
207 array(
208 'legacy_handle' => 'jquery-tiptip',
209 'handle' => 'wc-jquery-tiptip',
210 'path' => $plugin_url . '/assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js',
211 'dependencies' => array( 'jquery', 'wc-dompurify' ),
212 'version' => $version,
213 'args' => array(
214 'in_footer' => true,
215 ),
216 ),
217 array(
218 'legacy_handle' => 'round',
219 'handle' => 'wc-round',
220 'path' => $plugin_url . '/assets/js/round/round' . $suffix . '.js',
221 'dependencies' => array( 'jquery' ),
222 'version' => $version,
223 ),
224 array(
225 'handle' => 'wc-admin-meta-boxes',
226 'path' => $plugin_url . '/assets/js/admin/meta-boxes' . $suffix . '.js',
227 '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' ),
228 'version' => $version,
229 ),
230 array(
231 'legacy_handle' => 'qrcode',
232 'handle' => 'wc-qrcode',
233 'path' => $plugin_url . '/assets/js/jquery-qrcode/jquery.qrcode' . $suffix . '.js',
234 'dependencies' => array( 'jquery' ),
235 'version' => $version,
236 ),
237 array(
238 'legacy_handle' => 'stupidtable',
239 'handle' => 'wc-stupidtable',
240 'path' => $plugin_url . '/assets/js/stupidtable/stupidtable' . $suffix . '.js',
241 'dependencies' => array( 'jquery' ),
242 'version' => $version,
243 ),
244 array(
245 'legacy_handle' => 'serializejson',
246 'handle' => 'wc-serializejson',
247 'path' => $plugin_url . '/assets/js/jquery-serializejson/jquery.serializejson' . $suffix . '.js',
248 'dependencies' => array( 'jquery' ),
249 'version' => '2.8.1',
250 ),
251 array(
252 'legacy_handle' => 'flot',
253 'handle' => 'wc-flot',
254 'path' => $plugin_url . '/assets/js/jquery-flot/jquery.flot' . $suffix . '.js',
255 'dependencies' => array( 'jquery' ),
256 'version' => $version,
257 ),
258 array(
259 'legacy_handle' => 'flot-resize',
260 'handle' => 'wc-flot-resize',
261 'path' => $plugin_url . '/assets/js/jquery-flot/jquery.flot.resize' . $suffix . '.js',
262 'dependencies' => array( 'jquery', 'wc-flot' ),
263 'version' => $version,
264 ),
265 array(
266 'legacy_handle' => 'flot-time',
267 'handle' => 'wc-flot-time',
268 'path' => $plugin_url . '/assets/js/jquery-flot/jquery.flot.time' . $suffix . '.js',
269 'dependencies' => array( 'jquery', 'wc-flot' ),
270 'version' => $version,
271 ),
272 array(
273 'legacy_handle' => 'flot-pie',
274 'handle' => 'wc-flot-pie',
275 'path' => $plugin_url . '/assets/js/jquery-flot/jquery.flot.pie' . $suffix . '.js',
276 'dependencies' => array( 'jquery', 'wc-flot' ),
277 'version' => $version,
278 ),
279 array(
280 'legacy_handle' => 'flot-stack',
281 'handle' => 'wc-flot-stack',
282 'path' => $plugin_url . '/assets/js/jquery-flot/jquery.flot.stack' . $suffix . '.js',
283 'dependencies' => array( 'jquery', 'wc-flot' ),
284 'version' => $version,
285 ),
286 array(
287 'handle' => 'wc-settings-tax',
288 'path' => $plugin_url . '/assets/js/admin/settings-views-html-settings-tax' . $suffix . '.js',
289 'dependencies' => array( 'jquery', 'wp-util', 'underscore', 'backbone', 'wc-jquery-blockui' ),
290 'version' => $version,
291 ),
292 array(
293 'handle' => 'wc-backbone-modal',
294 'path' => $plugin_url . '/assets/js/admin/backbone-modal' . $suffix . '.js',
295 'dependencies' => array( 'underscore', 'backbone', 'wp-util' ),
296 'version' => $version,
297 ),
298 array(
299 'handle' => 'wc-shipping-zones',
300 'path' => $plugin_url . '/assets/js/admin/wc-shipping-zones' . $suffix . '.js',
301 'dependencies' => array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-enhanced-select', 'wc-backbone-modal' ),
302 'version' => $version,
303 ),
304 array(
305 'handle' => 'wc-shipping-zone-methods',
306 'path' => $plugin_url . '/assets/js/admin/wc-shipping-zone-methods' . $suffix . '.js',
307 'dependencies' => array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-backbone-modal' ),
308 'version' => $version,
309 ),
310 array(
311 'handle' => 'wc-shipping-classes',
312 'path' => $plugin_url . '/assets/js/admin/wc-shipping-classes' . $suffix . '.js',
313 'dependencies' => array( 'jquery', 'wp-util', 'underscore', 'backbone', 'wc-backbone-modal' ),
314 'version' => $version,
315 ),
316 array(
317 'handle' => 'wc-shipping-providers',
318 'path' => $plugin_url . '/assets/js/admin/wc-shipping-providers' . $suffix . '.js',
319 'dependencies' => array( 'jquery', 'wp-util', 'underscore', 'backbone', 'wc-backbone-modal' ),
320 'version' => $version,
321 ),
322 array(
323 'handle' => 'wc-clipboard',
324 'path' => $plugin_url . '/assets/js/admin/wc-clipboard' . $suffix . '.js',
325 'dependencies' => array( 'jquery' ),
326 'version' => $version,
327 ),
328 array(
329 'legacy_handle' => 'select2',
330 'handle' => 'wc-select2',
331 'path' => $plugin_url . '/assets/js/select2/select2.full' . $suffix . '.js',
332 'dependencies' => array( 'jquery' ),
333 'version' => '4.0.3',
334 ),
335 array(
336 'handle' => 'selectWoo',
337 'path' => $plugin_url . '/assets/js/selectWoo/selectWoo.full' . $suffix . '.js',
338 'dependencies' => array( 'jquery' ),
339 'version' => '1.0.6',
340 ),
341 array(
342 'handle' => 'wc-enhanced-select',
343 'path' => $plugin_url . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js',
344 'dependencies' => array( 'jquery', 'selectWoo' ),
345 'version' => $version,
346 ),
347 array(
348 'legacy_handle' => 'js-cookie',
349 'handle' => 'wc-js-cookie',
350 'path' => $plugin_url . '/assets/js/js-cookie/js.cookie' . $suffix . '.js',
351 'dependencies' => array(),
352 'version' => '2.1.4',
353 'args' => array(
354 'in_footer' => true,
355 ),
356 ),
357 array(
358 'legacy_handle' => 'dompurify',
359 'handle' => 'wc-dompurify',
360 'path' => $plugin_url . '/assets/js/dompurify/purify' . $suffix . '.js',
361 'dependencies' => array(),
362 'version' => $version,
363 ),
364 array(
365 'legacy_handle' => 'accounting',
366 'handle' => 'wc-accounting',
367 'path' => $plugin_url . '/assets/js/accounting/accounting' . $suffix . '.js',
368 'dependencies' => array( 'jquery' ),
369 'version' => '0.4.2',
370 ),
371 );
372 }
373
374 /**
375 * Register the scripts.
376 *
377 * These scripts are registered early to allow other
378 * plugins to take advantage of them by handle.
379 */
380 public function register_scripts() {
381 $scripts = $this->get_scripts();
382
383 foreach ( $scripts as $script ) {
384 wp_register_script(
385 $script['handle'],
386 $script['path'],
387 $script['dependencies'] ?? array(),
388 $script['version'] ?? null,
389 $script['args'] ?? array( 'in_footer' => false )
390 );
391
392 if ( isset( $script['legacy_handle'] ) ) {
393 wp_register_script(
394 $script['legacy_handle'],
395 false,
396 array( $script['handle'] ),
397 $script['version'] ?? null,
398 true
399 );
400 }
401 }
402
403 wp_localize_script(
404 'wc-enhanced-select',
405 'wc_enhanced_select_params',
406 array(
407 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ),
408 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ),
409 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ),
410 'i18n_input_too_short_n' => _x( 'Please enter %qty% or more characters', 'enhanced select', 'woocommerce' ),
411 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'woocommerce' ),
412 'i18n_input_too_long_n' => _x( 'Please delete %qty% characters', 'enhanced select', 'woocommerce' ),
413 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'woocommerce' ),
414 'i18n_selection_too_long_n' => _x( 'You can only select %qty% items', 'enhanced select', 'woocommerce' ),
415 'i18n_load_more' => _x( 'Loading more results&hellip;', 'enhanced select', 'woocommerce' ),
416 'i18n_searching' => _x( 'Searching&hellip;', 'enhanced select', 'woocommerce' ),
417 'ajax_url' => admin_url( 'admin-ajax.php' ),
418 'search_products_nonce' => wp_create_nonce( 'search-products' ),
419 'search_customers_nonce' => wp_create_nonce( 'search-customers' ),
420 'search_categories_nonce' => wp_create_nonce( 'search-categories' ),
421 'search_taxonomy_terms_nonce' => wp_create_nonce( 'search-taxonomy-terms' ),
422 'search_product_attributes_nonce' => wp_create_nonce( 'search-product-attributes' ),
423 'search_pages_nonce' => wp_create_nonce( 'search-pages' ),
424 'search_order_metakeys_nonce' => wp_create_nonce( 'search-order-metakeys' ),
425 )
426 );
427
428 wp_localize_script(
429 'wc-accounting',
430 'accounting_params',
431 array(
432 'mon_decimal_point' => wc_get_price_decimal_separator(),
433 )
434 );
435 }
436
437
438 /**
439 * Enqueue scripts.
440 */
441 public function admin_scripts() {
442 global $wp_query, $post, $theorder;
443
444 $screen = get_current_screen();
445 $screen_id = $screen ? $screen->id : '';
446 $wc_screen_id = 'woocommerce';
447 $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min';
448 $version = Constants::get_constant( 'WC_VERSION' );
449
450 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 ) );
451 wp_localize_script(
452 'wc-orders',
453 'wc_orders_params',
454 array(
455 'ajax_url' => admin_url( 'admin-ajax.php' ),
456 'preview_nonce' => wp_create_nonce( 'woocommerce-preview-order' ),
457 )
458 );
459
460 // WooCommerce admin pages.
461 if ( in_array( $screen_id, wc_get_screen_ids() ) ) {
462 wp_enqueue_script( 'iris' );
463 wp_enqueue_script( 'woocommerce_admin' );
464 wp_enqueue_script( 'wc-enhanced-select' );
465
466 $show_lost_connection_notice = $this->should_show_lost_connection_notice();
467
468 // The notice is toggled via heartbeat events (see woocommerce_admin.js), so ensure the emitter is loaded.
469 if ( $show_lost_connection_notice ) {
470 wp_enqueue_script( 'heartbeat' );
471 }
472
473 wp_enqueue_script( 'jquery-ui-sortable' );
474 wp_enqueue_script( 'jquery-ui-autocomplete' );
475
476 $locale = localeconv();
477 $decimal_point = isset( $locale['decimal_point'] ) ? $locale['decimal_point'] : '.';
478 $decimal = ( ! empty( wc_get_price_decimal_separator() ) ) ? wc_get_price_decimal_separator() : $decimal_point;
479
480 $params = array(
481 /* translators: %s: decimal */
482 'i18n_decimal_error' => sprintf( __( 'Please enter a value with one decimal point (%s) without thousand separators.', 'woocommerce' ), $decimal ),
483 /* translators: %s: price decimal separator */
484 '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() ),
485 'i18n_country_iso_error' => __( 'Please enter in country code with two capital letters.', 'woocommerce' ),
486 'i18n_sale_less_than_regular_error' => __( 'Please enter in a value less than the regular price.', 'woocommerce' ),
487 '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' ),
488 'i18n_remove_personal_data_notice' => __( 'This action cannot be reversed. Are you sure you wish to erase personal data from the selected orders?', 'woocommerce' ),
489 'i18n_confirm_delete' => __( 'Are you sure you wish to delete this item?', 'woocommerce' ),
490 'i18n_global_unique_id_error' => __( 'Enter only numbers and hyphens (-). The letter X is allowed only as the final ISBN-10 check digit.', 'woocommerce' ),
491 'decimal_point' => $decimal,
492 'mon_decimal_point' => wc_get_price_decimal_separator(),
493 'ajax_url' => admin_url( 'admin-ajax.php' ),
494 'strings' => array(
495 'import_products' => __( 'Import', 'woocommerce' ),
496 'export_products' => __( 'Export', 'woocommerce' ),
497 // translators: %d: number of selected products.
498 'export_selected_products' => __( 'Export %d selected', 'woocommerce' ),
499 ),
500 'nonces' => array(
501 'gateway_toggle' => current_user_can( 'manage_woocommerce' ) ? wp_create_nonce( 'woocommerce-toggle-payment-gateway-enabled' ) : null,
502 'export_selected_products_nonce' => current_user_can( 'export' ) ? wp_create_nonce( 'export-selected-products' ) : null,
503 ),
504 'urls' => array(
505 'add_product' => null,
506 'import_products' => current_user_can( 'import' ) ? esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_importer' ) ) : null,
507 'export_products' => current_user_can( 'export' ) ? esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_exporter' ) ) : null,
508 ),
509 'show_lost_connection_notice' => $show_lost_connection_notice,
510 );
511
512 wp_localize_script( 'woocommerce_admin', 'woocommerce_admin', $params );
513 }
514
515 // Edit product category pages.
516 if ( in_array( $screen_id, array( 'edit-product_cat' ) ) ) {
517 wp_enqueue_media();
518 }
519
520 // Products.
521 if ( in_array( $screen_id, array( 'edit-product' ) ) ) {
522 wp_enqueue_script( 'woocommerce_quick-edit', WC()->plugin_url() . '/assets/js/admin/quick-edit' . $suffix . '.js', array( 'jquery', 'woocommerce_admin' ), $version );
523
524 $params = array(
525 'strings' => array(
526 'allow_reviews' => esc_js( __( 'Enable reviews', 'woocommerce' ) ),
527 ),
528 );
529
530 wp_localize_script( 'woocommerce_quick-edit', 'woocommerce_quick_edit', $params );
531 }
532
533 // Product description.
534 if ( in_array( $screen_id, array( 'product' ), true ) ) {
535 wp_enqueue_script( 'wc-admin-product-editor', WC()->plugin_url() . '/assets/js/admin/product-editor' . $suffix . '.js', array( 'jquery' ), $version, false );
536
537 wp_localize_script(
538 'wc-admin-product-editor',
539 'woocommerce_admin_product_editor',
540 array(
541 'i18n_description' => esc_js( __( 'Product description', 'woocommerce' ) ),
542 )
543 );
544 }
545
546 // Meta boxes.
547 /* phpcs:disable */
548 if ( in_array( $screen_id, array( 'product', 'edit-product' ) ) ) {
549 wp_enqueue_media();
550 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 );
551 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 );
552
553 wp_enqueue_script( 'wc-admin-product-meta-boxes' );
554 wp_enqueue_script( 'wc-admin-variation-meta-boxes' );
555
556 $params = array(
557 'post_id' => isset( $post->ID ) ? $post->ID : '',
558 'plugin_url' => WC()->plugin_url(),
559 'ajax_url' => admin_url( 'admin-ajax.php' ),
560 'woocommerce_placeholder_img_src' => wc_placeholder_img_src(),
561 'add_variation_nonce' => wp_create_nonce( 'add-variation' ),
562 'link_variation_nonce' => wp_create_nonce( 'link-variations' ),
563 'delete_variations_nonce' => wp_create_nonce( 'delete-variations' ),
564 'load_variations_nonce' => wp_create_nonce( 'load-variations' ),
565 'save_variations_nonce' => wp_create_nonce( 'save-variations' ),
566 'bulk_edit_variations_nonce' => wp_create_nonce( 'bulk-edit-variations' ),
567 /* translators: %d: Number of variations */
568 '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 ) ),
569 'i18n_enter_a_value' => esc_js( __( 'Enter a value', 'woocommerce' ) ),
570 'i18n_enter_menu_order' => esc_js( __( 'Variation menu order (determines position in the list of variations)', 'woocommerce' ) ),
571 'i18n_enter_a_value_fixed_or_percent' => esc_js( __( 'Enter a value (fixed or %)', 'woocommerce' ) ),
572 'i18n_sale_price_warning' => esc_js( __( 'Warning: Sale prices will be removed if they are not lower than regular prices.', 'woocommerce' ) ),
573 'i18n_delete_all_variations' => esc_js( __( 'Are you sure you want to delete all variations? This cannot be undone.', 'woocommerce' ) ),
574 'i18n_last_warning' => esc_js( __( 'Last warning, are you sure?', 'woocommerce' ) ),
575 'i18n_choose_image' => esc_js( __( 'Choose an image', 'woocommerce' ) ),
576 'i18n_set_image' => esc_js( __( 'Set variation image', 'woocommerce' ) ),
577 'i18n_variation_added' => esc_js( __( '1 variation added', 'woocommerce' ) ),
578 'i18n_variations_added' => esc_js( __( '%qty% variations added', 'woocommerce' ) ),
579 'i18n_remove_variation' => esc_js( __( 'Are you sure you want to remove this variation?', 'woocommerce' ) ),
580 'i18n_scheduled_sale_start' => esc_js( __( 'Sale start date (YYYY-MM-DD format or leave blank)', 'woocommerce' ) ),
581 'i18n_scheduled_sale_end' => esc_js( __( 'Sale end date (YYYY-MM-DD format or leave blank)', 'woocommerce' ) ),
582 'i18n_scheduled_sale_end_before_start' => esc_js( __( 'The sale end date cannot be earlier than the sale start date.', 'woocommerce' ) ),
583 'i18n_edited_variations' => esc_js( __( 'Save changes before changing page?', 'woocommerce' ) ),
584 'i18n_variation_count_single' => esc_js( __( '1 variation', 'woocommerce' ) ),
585 'i18n_variation_count_plural' => esc_js( __( '%qty% variations', 'woocommerce' ) ),
586 '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' ) ),
587 'variations_per_page' => absint( apply_filters( 'woocommerce_admin_meta_boxes_variations_per_page', 15 ) ),
588 );
589
590 wp_localize_script( 'wc-admin-variation-meta-boxes', 'woocommerce_admin_meta_boxes_variations', $params );
591 }
592 /* phpcs: enable */
593 if ( $this->is_order_meta_box_screen( $screen_id ) ) {
594 $default_location = wc_get_customer_default_location();
595
596 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 );
597 wp_localize_script(
598 'wc-admin-order-meta-boxes',
599 'woocommerce_admin_meta_boxes_order',
600 array(
601 'countries' => wp_json_encode(
602 array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ),
603 JSON_HEX_TAG | JSON_UNESCAPED_SLASHES
604 ),
605 'i18n_select_state_text' => esc_attr__( 'Select an option&hellip;', 'woocommerce' ),
606 'default_country' => isset( $default_location['country'] ) ? $default_location['country'] : '',
607 'default_state' => isset( $default_location['state'] ) ? $default_location['state'] : '',
608 'placeholder_name' => esc_attr__( 'Name (required)', 'woocommerce' ),
609 'placeholder_value' => esc_attr__( 'Value (required)', 'woocommerce' ),
610 )
611 );
612 }
613 /* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */
614 if ( in_array( $screen_id, array( 'shop_coupon', 'edit-shop_coupon' ) ) ) {
615 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 );
616 wp_localize_script(
617 'wc-admin-coupon-meta-boxes',
618 'woocommerce_admin_meta_boxes_coupon',
619 array(
620 'generate_button_text' => esc_html__( 'Generate coupon code', 'woocommerce' ),
621 'characters' => apply_filters( 'woocommerce_coupon_code_generator_characters', 'ABCDEFGHJKMNPQRSTUVWXYZ23456789' ),
622 'char_length' => apply_filters( 'woocommerce_coupon_code_generator_character_length', 8 ),
623 'prefix' => apply_filters( 'woocommerce_coupon_code_generator_prefix', '' ),
624 'suffix' => apply_filters( 'woocommerce_coupon_code_generator_suffix', '' ),
625 )
626 );
627 }
628 /* phpcs: enable */
629 if ( in_array( str_replace( 'edit-', '', $screen_id ), array( 'shop_coupon', 'product' ), true ) || $this->is_order_meta_box_screen( $screen_id ) ) {
630 $post_id = isset( $post->ID ) ? $post->ID : '';
631 $currency = '';
632 $remove_item_notice = __( 'Are you sure you want to remove the selected items?', 'woocommerce' );
633 $remove_fee_notice = __( 'Are you sure you want to remove the selected fees?', 'woocommerce' );
634 $remove_shipping_notice = __( 'Are you sure you want to remove the selected shipping?', 'woocommerce' );
635
636 // Eventually this will become wc_data_or_post object as we implement more custom tables.
637 $order_or_post_object = $post;
638 if ( ( $theorder instanceof WC_Order ) && $this->is_order_meta_box_screen( $screen_id ) ) {
639 $order_or_post_object = $theorder;
640 if ( $order_or_post_object ) {
641 $currency = $order_or_post_object->get_currency();
642
643 if ( ! $order_or_post_object->has_status( array( OrderStatus::PENDING, OrderStatus::FAILED, OrderStatus::CANCELLED ) ) ) {
644 $remove_item_notice = $remove_item_notice . ' ' . __( "You may need to manually restore the item's stock.", 'woocommerce' );
645 }
646 }
647 }
648
649 $params = array(
650 'remove_item_notice' => $remove_item_notice,
651 'remove_fee_notice' => $remove_fee_notice,
652 'remove_shipping_notice' => $remove_shipping_notice,
653 'i18n_select_items' => __( 'Please select some items.', 'woocommerce' ),
654 'i18n_do_refund' => __( 'Are you sure you wish to process this refund? This action cannot be undone.', 'woocommerce' ),
655 'i18n_delete_refund' => __( 'Are you sure you wish to delete this refund? This action cannot be undone.', 'woocommerce' ),
656 'i18n_delete_tax' => __( 'Are you sure you wish to delete this tax column? This action cannot be undone.', 'woocommerce' ),
657 'remove_item_meta' => __( 'Remove this item meta?', 'woocommerce' ),
658 'name_label' => __( 'Name', 'woocommerce' ),
659 'remove_label' => __( 'Remove', 'woocommerce' ),
660 'click_to_toggle' => __( 'Click to toggle', 'woocommerce' ),
661 'values_label' => __( 'Value(s)', 'woocommerce' ),
662 'text_attribute_tip' => __( 'Enter some text, or some attributes by pipe (|) separating values.', 'woocommerce' ),
663 'visible_label' => __( 'Visible on the product page', 'woocommerce' ),
664 'used_for_variations_label' => __( 'Used for variations', 'woocommerce' ),
665 'new_attribute_prompt' => __( 'Enter a name for the new attribute term:', 'woocommerce' ),
666 'calc_totals' => __( 'Recalculate totals? This will calculate taxes based on the customers country (or the store base country) and update totals.', 'woocommerce' ),
667 'copy_billing' => __( 'Copy billing information to shipping information? This will remove any currently entered shipping information.', 'woocommerce' ),
668 'load_billing' => __( "Load the customer's billing information? This will remove any currently entered billing information.", 'woocommerce' ),
669 'load_shipping' => __( "Load the customer's shipping information? This will remove any currently entered shipping information.", 'woocommerce' ),
670 'featured_label' => __( 'Featured', 'woocommerce' ),
671 'prices_include_tax' => esc_attr( get_option( 'woocommerce_prices_include_tax' ) ),
672 'tax_based_on' => esc_attr( get_option( 'woocommerce_tax_based_on' ) ),
673 'round_at_subtotal' => esc_attr( get_option( 'woocommerce_tax_round_at_subtotal' ) ),
674 'no_customer_selected' => __( 'No customer selected', 'woocommerce' ),
675 'plugin_url' => WC()->plugin_url(),
676 'ajax_url' => admin_url( 'admin-ajax.php' ),
677 'order_item_nonce' => wp_create_nonce( 'order-item' ),
678 'add_attribute_nonce' => wp_create_nonce( 'add-attribute' ),
679 'save_attributes_nonce' => wp_create_nonce( 'save-attributes' ),
680 'add_attributes_and_variations' => wp_create_nonce( 'add-attributes-and-variations' ),
681 'calc_totals_nonce' => wp_create_nonce( 'calc-totals' ),
682 'get_customer_details_nonce' => wp_create_nonce( 'get-customer-details' ),
683 'search_products_nonce' => wp_create_nonce( 'search-products' ),
684 'grant_access_nonce' => wp_create_nonce( 'grant-access' ),
685 'revoke_access_nonce' => wp_create_nonce( 'revoke-access' ),
686 'add_order_note_nonce' => wp_create_nonce( 'add-order-note' ),
687 'delete_order_note_nonce' => wp_create_nonce( 'delete-order-note' ),
688 'calendar_image' => WC()->plugin_url() . '/assets/images/calendar.png',
689 '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,
690 'base_country' => WC()->countries->get_base_country(),
691 'currency_format_num_decimals' => wc_get_price_decimals(),
692 'currency_format_symbol' => get_woocommerce_currency_symbol( $currency ),
693 'currency_format_decimal_sep' => esc_attr( wc_get_price_decimal_separator() ),
694 'currency_format_thousand_sep' => esc_attr( wc_get_price_thousand_separator() ),
695 'currency_format' => esc_attr( str_replace( array( '%1$s', '%2$s' ), array( '%s', '%v' ), get_woocommerce_price_format() ) ), // For accounting JS.
696 'rounding_precision' => wc_get_rounding_precision(),
697 'tax_rounding_mode' => wc_get_tax_rounding_mode(),
698 'product_types' => array_unique( array_merge( array( ProductType::SIMPLE, ProductType::GROUPED, ProductType::VARIABLE, ProductType::EXTERNAL ), array_keys( wc_get_product_types() ) ) ),
699 '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' ),
700 'i18n_permission_revoke' => __( 'Are you sure you want to revoke access to this download?', 'woocommerce' ),
701 'i18n_tax_rate_already_exists' => __( 'You cannot add the same tax rate twice!', 'woocommerce' ),
702 'i18n_delete_note' => __( 'Are you sure you wish to delete this note? This action cannot be undone.', 'woocommerce' ),
703 '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' ),
704 'i18n_no_notes_yet' => __( 'There are no notes yet.', 'woocommerce' ),
705 'i18n_order_note_added' => __( 'Order note added.', 'woocommerce' ),
706 'i18n_customer_order_note_added' => __( 'Order note added and emailed to the customer.', 'woocommerce' ),
707 'i18n_apply_coupon' => __( 'Enter a coupon code to apply. Discounts are applied to line totals, before taxes.', 'woocommerce' ),
708 'i18n_add_fee' => __( 'Enter a fixed amount or percentage to apply as a fee.', 'woocommerce' ),
709 'i18n_attribute_name_placeholder' => __( 'New attribute', 'woocommerce' ),
710 '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' ),
711 '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' ),
712 'i18n_product_external_tip' => __( '<b>External or Affiliate –</b> one that you list and describe on your website but is sold elsewhere.', 'woocommerce' ),
713 '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' ),
714 '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' ),
715 'i18n_product_description_tip' => __( 'Describe this product. What makes it unique? What are its most important features?', 'woocommerce' ),
716 'i18n_product_short_description_tip' => __( 'Summarize this product in 1-2 short sentences. We’ll show it at the top of the page.', 'woocommerce' ),
717 'i18n_save_attribute_variation_tip' => __( 'Make sure you enter the name and values for each attribute.', 'woocommerce' ),
718 /* translators: %1$s: maximum file size */
719 '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() ) ),
720 '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' ),
721 'i18n_add_attribute_error_notice' => __( 'Adding new attribute failed.', 'woocommerce' ),
722 /* translators: %s: WC_DELIMITER */
723 'i18n_attributes_default_placeholder' => sprintf( esc_attr__( 'Enter some descriptive text. Use “%s” to separate different values.', 'woocommerce' ), esc_attr( WC_DELIMITER ) ),
724 '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 ) )
725 );
726
727 $cogs_controller = wc_get_container()->get( CostOfGoodsSoldController::class );
728 if( $cogs_controller->feature_is_enabled() ) {
729 $params['cogs_value_tooltip_simple_products'] = esc_attr( $cogs_controller->get_general_cost_edit_field_tooltip( false ) );
730 $params['cogs_value_tooltip_variable_products'] = esc_attr( $cogs_controller->get_general_cost_edit_field_tooltip( true ) );
731 }
732 wp_localize_script( 'wc-admin-meta-boxes', 'woocommerce_admin_meta_boxes', $params );
733 }
734
735 // Term ordering - only when sorting by term_order.
736 /* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */
737 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'] ) ) {
738
739 wp_register_script( 'woocommerce_term_ordering', WC()->plugin_url() . '/assets/js/admin/term-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), $version );
740 wp_enqueue_script( 'woocommerce_term_ordering' );
741
742 $taxonomy = isset( $_GET['taxonomy'] ) ? wc_clean( wp_unslash( $_GET['taxonomy'] ) ) : '';
743
744 $woocommerce_term_order_params = array(
745 'taxonomy' => $taxonomy,
746 'nonce' => wp_create_nonce( 'term-ordering' ),
747 );
748
749 wp_localize_script( 'woocommerce_term_ordering', 'woocommerce_term_ordering_params', $woocommerce_term_order_params );
750 }
751 /* phpcs: enable */
752
753 // Product sorting - only when sorting by menu order on the products page.
754 if ( current_user_can( 'edit_others_pages' ) && 'edit-product' === $screen_id && isset( $wp_query->query['orderby'] ) && 'menu_order title' === $wp_query->query['orderby'] ) {
755 wp_register_script( 'woocommerce_product_ordering', WC()->plugin_url() . '/assets/js/admin/product-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), $version, true );
756 wp_enqueue_script( 'woocommerce_product_ordering' );
757
758 wp_localize_script(
759 'woocommerce_product_ordering',
760 'woocommerce_product_ordering_params',
761 array( 'nonce' => wp_create_nonce( 'product-ordering' ) )
762 );
763 }
764
765 // Reports Pages.
766 /* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */
767 if ( in_array( $screen_id, apply_filters( 'woocommerce_reports_screen_ids', array( $wc_screen_id . '_page_wc-reports', 'toplevel_page_wc-reports' ) ) ) ) {
768 wp_register_script( 'wc-reports', WC()->plugin_url() . '/assets/js/admin/reports' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker' ), $version );
769
770 wp_enqueue_script( 'wc-reports' );
771 wp_enqueue_script( 'wc-flot' );
772 wp_enqueue_script( 'wc-flot-resize' );
773 wp_enqueue_script( 'wc-flot-time' );
774 wp_enqueue_script( 'wc-flot-pie' );
775 wp_enqueue_script( 'wc-flot-stack' );
776 }
777 /* phpcs: enable */
778
779 // API settings.
780 if ( $wc_screen_id . '_page_wc-settings' === $screen_id && isset( $_GET['section'] ) && 'keys' == $_GET['section'] ) {
781 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 );
782 wp_enqueue_script( 'wc-api-keys' );
783 wp_localize_script(
784 'wc-api-keys',
785 'woocommerce_admin_api_keys',
786 array(
787 'ajax_url' => admin_url( 'admin-ajax.php' ),
788 'update_api_nonce' => wp_create_nonce( 'update-api-key' ),
789 'clipboard_failed' => esc_html__( 'Copying to clipboard failed. Please press Ctrl/Cmd+C to copy.', 'woocommerce' ),
790 )
791 );
792 }
793
794 // Email settings.
795 if ( $wc_screen_id . '_page_wc-settings' === $screen_id && isset( $_GET['tab'] ) && 'email' === $_GET['tab'] ) {
796 wp_enqueue_media();
797 }
798
799 // System status.
800 if ( $wc_screen_id . '_page_wc-status' === $screen_id ) {
801 wp_register_script( 'wc-admin-system-status', WC()->plugin_url() . '/assets/js/admin/system-status' . $suffix . '.js', array( 'wc-clipboard' ), $version );
802 wp_enqueue_script( 'wc-admin-system-status' );
803 wp_localize_script(
804 'wc-admin-system-status',
805 'woocommerce_admin_system_status',
806 array(
807 'delete_log_confirmation' => esc_js( __( 'Are you sure you want to delete this log?', 'woocommerce' ) ),
808 'run_tool_confirmation' => esc_js( __( 'Are you sure you want to run this tool?', 'woocommerce' ) ),
809 'tools_poll_interval' => 10000,
810 'tools_url' => esc_url_raw( admin_url( 'admin.php?page=wc-status&tab=tools' ) ),
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