helper
3 years ago
importers
3 years ago
list-tables
3 years ago
marketplace-suggestions
3 years ago
meta-boxes
3 years ago
notes
3 years ago
plugin-updates
5 years ago
reports
3 years ago
settings
3 years ago
views
3 years ago
class-wc-admin-addons.php
3 years ago
class-wc-admin-api-keys-table-list.php
6 years ago
class-wc-admin-api-keys.php
6 years ago
class-wc-admin-assets.php
3 years ago
class-wc-admin-attributes.php
3 years ago
class-wc-admin-customize.php
5 years ago
class-wc-admin-dashboard-setup.php
3 years ago
class-wc-admin-dashboard.php
3 years ago
class-wc-admin-duplicate-product.php
5 years ago
class-wc-admin-exporters.php
3 years ago
class-wc-admin-help.php
4 years ago
class-wc-admin-importers.php
5 years ago
class-wc-admin-log-table-list.php
5 years ago
class-wc-admin-menus.php
3 years ago
class-wc-admin-meta-boxes.php
3 years ago
class-wc-admin-notices.php
3 years ago
class-wc-admin-permalink-settings.php
5 years ago
class-wc-admin-pointers.php
3 years ago
class-wc-admin-post-types.php
3 years ago
class-wc-admin-profile.php
4 years ago
class-wc-admin-reports.php
5 years ago
class-wc-admin-settings.php
3 years ago
class-wc-admin-setup-wizard.php
4 years ago
class-wc-admin-status.php
3 years ago
class-wc-admin-taxonomies.php
3 years ago
class-wc-admin-webhooks-table-list.php
4 years ago
class-wc-admin-webhooks.php
3 years ago
class-wc-admin.php
4 years ago
wc-admin-functions.php
3 years ago
wc-meta-box-functions.php
3 years ago
class-wc-admin-assets.php
564 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 | |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit; |
| 14 | } |
| 15 | |
| 16 | if ( ! class_exists( 'WC_Admin_Assets', false ) ) : |
| 17 | |
| 18 | /** |
| 19 | * WC_Admin_Assets Class. |
| 20 | */ |
| 21 | class WC_Admin_Assets { |
| 22 | |
| 23 | /** |
| 24 | * Hook in tabs. |
| 25 | */ |
| 26 | public function __construct() { |
| 27 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ) ); |
| 28 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Enqueue styles. |
| 33 | */ |
| 34 | public function admin_styles() { |
| 35 | global $wp_scripts; |
| 36 | |
| 37 | $version = Constants::get_constant( 'WC_VERSION' ); |
| 38 | $screen = get_current_screen(); |
| 39 | $screen_id = $screen ? $screen->id : ''; |
| 40 | |
| 41 | // Register admin styles. |
| 42 | wp_register_style( 'woocommerce_admin_menu_styles', WC()->plugin_url() . '/assets/css/menu.css', array(), $version ); |
| 43 | wp_register_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), $version ); |
| 44 | wp_register_style( 'jquery-ui-style', WC()->plugin_url() . '/assets/css/jquery-ui/jquery-ui.min.css', array(), $version ); |
| 45 | wp_register_style( 'woocommerce_admin_dashboard_styles', WC()->plugin_url() . '/assets/css/dashboard.css', array(), $version ); |
| 46 | wp_register_style( 'woocommerce_admin_print_reports_styles', WC()->plugin_url() . '/assets/css/reports-print.css', array(), $version, 'print' ); |
| 47 | wp_register_style( 'woocommerce_admin_marketplace_styles', WC()->plugin_url() . '/assets/css/marketplace-suggestions.css', array(), $version ); |
| 48 | wp_register_style( 'woocommerce_admin_privacy_styles', WC()->plugin_url() . '/assets/css/privacy.css', array(), $version ); |
| 49 | |
| 50 | // Add RTL support for admin styles. |
| 51 | wp_style_add_data( 'woocommerce_admin_menu_styles', 'rtl', 'replace' ); |
| 52 | wp_style_add_data( 'woocommerce_admin_styles', 'rtl', 'replace' ); |
| 53 | wp_style_add_data( 'woocommerce_admin_dashboard_styles', 'rtl', 'replace' ); |
| 54 | wp_style_add_data( 'woocommerce_admin_print_reports_styles', 'rtl', 'replace' ); |
| 55 | wp_style_add_data( 'woocommerce_admin_marketplace_styles', 'rtl', 'replace' ); |
| 56 | wp_style_add_data( 'woocommerce_admin_privacy_styles', 'rtl', 'replace' ); |
| 57 | |
| 58 | if ( $screen && $screen->is_block_editor() ) { |
| 59 | wp_register_style( 'woocommerce-general', WC()->plugin_url() . '/assets/css/woocommerce.css', array(), $version ); |
| 60 | wp_style_add_data( 'woocommerce-general', 'rtl', 'replace' ); |
| 61 | if ( wc_current_theme_is_fse_theme() ) { |
| 62 | wp_register_style( 'woocommerce-blocktheme', WC()->plugin_url() . '/assets/css/woocommerce-blocktheme.css', array(), $version ); |
| 63 | wp_style_add_data( 'woocommerce-blocktheme', 'rtl', 'replace' ); |
| 64 | wp_enqueue_style( 'woocommerce-blocktheme' ); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | // Sitewide menu CSS. |
| 69 | wp_enqueue_style( 'woocommerce_admin_menu_styles' ); |
| 70 | |
| 71 | // Admin styles for WC pages only. |
| 72 | if ( in_array( $screen_id, wc_get_screen_ids() ) ) { |
| 73 | wp_enqueue_style( 'woocommerce_admin_styles' ); |
| 74 | wp_enqueue_style( 'jquery-ui-style' ); |
| 75 | wp_enqueue_style( 'wp-color-picker' ); |
| 76 | } |
| 77 | |
| 78 | if ( in_array( $screen_id, array( 'dashboard' ) ) ) { |
| 79 | wp_enqueue_style( 'woocommerce_admin_dashboard_styles' ); |
| 80 | } |
| 81 | |
| 82 | if ( in_array( $screen_id, array( 'woocommerce_page_wc-reports', 'toplevel_page_wc-reports' ) ) ) { |
| 83 | wp_enqueue_style( 'woocommerce_admin_print_reports_styles' ); |
| 84 | } |
| 85 | |
| 86 | // Privacy Policy Guide css for back-compat. |
| 87 | if ( isset( $_GET['wp-privacy-policy-guide'] ) || in_array( $screen_id, array( 'privacy-policy-guide' ) ) ) { |
| 88 | wp_enqueue_style( 'woocommerce_admin_privacy_styles' ); |
| 89 | } |
| 90 | |
| 91 | // @deprecated 2.3. |
| 92 | if ( has_action( 'woocommerce_admin_css' ) ) { |
| 93 | /* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */ |
| 94 | do_action( 'woocommerce_admin_css' ); |
| 95 | /* phpcs: enable */ |
| 96 | wc_deprecated_function( 'The woocommerce_admin_css action', '2.3', 'admin_enqueue_scripts' ); |
| 97 | } |
| 98 | |
| 99 | if ( WC_Marketplace_Suggestions::show_suggestions_for_screen( $screen_id ) ) { |
| 100 | wp_enqueue_style( 'woocommerce_admin_marketplace_styles' ); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | |
| 105 | /** |
| 106 | * Enqueue scripts. |
| 107 | */ |
| 108 | public function admin_scripts() { |
| 109 | global $wp_query, $post, $theorder; |
| 110 | |
| 111 | $screen = get_current_screen(); |
| 112 | $screen_id = $screen ? $screen->id : ''; |
| 113 | $wc_screen_id = 'woocommerce'; |
| 114 | $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; |
| 115 | $version = Constants::get_constant( 'WC_VERSION' ); |
| 116 | |
| 117 | // Register scripts. |
| 118 | wp_register_script( 'woocommerce_admin', WC()->plugin_url() . '/assets/js/admin/woocommerce_admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui', 'jquery-ui-sortable', 'jquery-ui-widget', 'jquery-ui-core', 'jquery-tiptip' ), $version ); |
| 119 | wp_register_script( 'jquery-blockui', WC()->plugin_url() . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), '2.70', true ); |
| 120 | wp_register_script( 'jquery-tiptip', WC()->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js', array( 'jquery' ), $version, true ); |
| 121 | wp_register_script( 'round', WC()->plugin_url() . '/assets/js/round/round' . $suffix . '.js', array( 'jquery' ), $version ); |
| 122 | wp_register_script( 'wc-admin-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'accounting', 'round', 'wc-enhanced-select', 'plupload-all', 'stupidtable', 'jquery-tiptip' ), $version ); |
| 123 | wp_register_script( 'qrcode', WC()->plugin_url() . '/assets/js/jquery-qrcode/jquery.qrcode' . $suffix . '.js', array( 'jquery' ), $version ); |
| 124 | wp_register_script( 'stupidtable', WC()->plugin_url() . '/assets/js/stupidtable/stupidtable' . $suffix . '.js', array( 'jquery' ), $version ); |
| 125 | wp_register_script( 'serializejson', WC()->plugin_url() . '/assets/js/jquery-serializejson/jquery.serializejson' . $suffix . '.js', array( 'jquery' ), '2.8.1' ); |
| 126 | wp_register_script( 'flot', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot' . $suffix . '.js', array( 'jquery' ), $version ); |
| 127 | wp_register_script( 'flot-resize', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.resize' . $suffix . '.js', array( 'jquery', 'flot' ), $version ); |
| 128 | wp_register_script( 'flot-time', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.time' . $suffix . '.js', array( 'jquery', 'flot' ), $version ); |
| 129 | wp_register_script( 'flot-pie', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.pie' . $suffix . '.js', array( 'jquery', 'flot' ), $version ); |
| 130 | wp_register_script( 'flot-stack', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.stack' . $suffix . '.js', array( 'jquery', 'flot' ), $version ); |
| 131 | wp_register_script( 'wc-settings-tax', WC()->plugin_url() . '/assets/js/admin/settings-views-html-settings-tax' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-blockui' ), $version ); |
| 132 | wp_register_script( 'wc-backbone-modal', WC()->plugin_url() . '/assets/js/admin/backbone-modal' . $suffix . '.js', array( 'underscore', 'backbone', 'wp-util' ), $version ); |
| 133 | wp_register_script( 'wc-shipping-zones', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zones' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-enhanced-select', 'wc-backbone-modal' ), $version ); |
| 134 | wp_register_script( 'wc-shipping-zone-methods', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zone-methods' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-backbone-modal' ), $version ); |
| 135 | wp_register_script( 'wc-shipping-classes', WC()->plugin_url() . '/assets/js/admin/wc-shipping-classes' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone' ), $version ); |
| 136 | wp_register_script( 'wc-clipboard', WC()->plugin_url() . '/assets/js/admin/wc-clipboard' . $suffix . '.js', array( 'jquery' ), $version ); |
| 137 | wp_register_script( 'select2', WC()->plugin_url() . '/assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), '4.0.3' ); |
| 138 | wp_register_script( 'selectWoo', WC()->plugin_url() . '/assets/js/selectWoo/selectWoo.full' . $suffix . '.js', array( 'jquery' ), '1.0.6' ); |
| 139 | wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'selectWoo' ), $version ); |
| 140 | wp_register_script( 'js-cookie', WC()->plugin_url() . '/assets/js/js-cookie/js.cookie' . $suffix . '.js', array(), '2.1.4', true ); |
| 141 | |
| 142 | wp_localize_script( |
| 143 | 'wc-enhanced-select', |
| 144 | 'wc_enhanced_select_params', |
| 145 | array( |
| 146 | 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ), |
| 147 | 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ), |
| 148 | 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ), |
| 149 | 'i18n_input_too_short_n' => _x( 'Please enter %qty% or more characters', 'enhanced select', 'woocommerce' ), |
| 150 | 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'woocommerce' ), |
| 151 | 'i18n_input_too_long_n' => _x( 'Please delete %qty% characters', 'enhanced select', 'woocommerce' ), |
| 152 | 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'woocommerce' ), |
| 153 | 'i18n_selection_too_long_n' => _x( 'You can only select %qty% items', 'enhanced select', 'woocommerce' ), |
| 154 | 'i18n_load_more' => _x( 'Loading more results…', 'enhanced select', 'woocommerce' ), |
| 155 | 'i18n_searching' => _x( 'Searching…', 'enhanced select', 'woocommerce' ), |
| 156 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 157 | 'search_products_nonce' => wp_create_nonce( 'search-products' ), |
| 158 | 'search_customers_nonce' => wp_create_nonce( 'search-customers' ), |
| 159 | 'search_categories_nonce' => wp_create_nonce( 'search-categories' ), |
| 160 | 'search_taxonomy_terms_nonce' => wp_create_nonce( 'search-taxonomy-terms' ), |
| 161 | 'search_product_attributes_nonce' => wp_create_nonce( 'search-product-attributes' ), |
| 162 | 'search_pages_nonce' => wp_create_nonce( 'search-pages' ), |
| 163 | ) |
| 164 | ); |
| 165 | |
| 166 | wp_register_script( 'accounting', WC()->plugin_url() . '/assets/js/accounting/accounting' . $suffix . '.js', array( 'jquery' ), '0.4.2' ); |
| 167 | wp_localize_script( |
| 168 | 'accounting', |
| 169 | 'accounting_params', |
| 170 | array( |
| 171 | 'mon_decimal_point' => wc_get_price_decimal_separator(), |
| 172 | ) |
| 173 | ); |
| 174 | |
| 175 | wp_register_script( 'wc-orders', WC()->plugin_url() . '/assets/js/admin/wc-orders' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-blockui' ), $version ); |
| 176 | wp_localize_script( |
| 177 | 'wc-orders', |
| 178 | 'wc_orders_params', |
| 179 | array( |
| 180 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 181 | 'preview_nonce' => wp_create_nonce( 'woocommerce-preview-order' ), |
| 182 | ) |
| 183 | ); |
| 184 | |
| 185 | // WooCommerce admin pages. |
| 186 | if ( in_array( $screen_id, wc_get_screen_ids() ) ) { |
| 187 | wp_enqueue_script( 'iris' ); |
| 188 | wp_enqueue_script( 'woocommerce_admin' ); |
| 189 | wp_enqueue_script( 'wc-enhanced-select' ); |
| 190 | wp_enqueue_script( 'jquery-ui-sortable' ); |
| 191 | wp_enqueue_script( 'jquery-ui-autocomplete' ); |
| 192 | |
| 193 | $locale = localeconv(); |
| 194 | $decimal_point = isset( $locale['decimal_point'] ) ? $locale['decimal_point'] : '.'; |
| 195 | $decimal = ( ! empty( wc_get_price_decimal_separator() ) ) ? wc_get_price_decimal_separator() : $decimal_point; |
| 196 | |
| 197 | $params = array( |
| 198 | /* translators: %s: decimal */ |
| 199 | 'i18n_decimal_error' => sprintf( __( 'Please enter a value with one decimal point (%s) without thousand separators.', 'woocommerce' ), $decimal ), |
| 200 | /* translators: %s: price decimal separator */ |
| 201 | '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() ), |
| 202 | 'i18n_country_iso_error' => __( 'Please enter in country code with two capital letters.', 'woocommerce' ), |
| 203 | 'i18n_sale_less_than_regular_error' => __( 'Please enter in a value less than the regular price.', 'woocommerce' ), |
| 204 | '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' ), |
| 205 | 'i18n_remove_personal_data_notice' => __( 'This action cannot be reversed. Are you sure you wish to erase personal data from the selected orders?', 'woocommerce' ), |
| 206 | 'i18n_confirm_delete' => __( 'Are you sure you wish to delete this item?', 'woocommerce' ), |
| 207 | 'decimal_point' => $decimal, |
| 208 | 'mon_decimal_point' => wc_get_price_decimal_separator(), |
| 209 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 210 | 'strings' => array( |
| 211 | 'import_products' => __( 'Import', 'woocommerce' ), |
| 212 | 'export_products' => __( 'Export', 'woocommerce' ), |
| 213 | ), |
| 214 | 'nonces' => array( |
| 215 | 'gateway_toggle' => wp_create_nonce( 'woocommerce-toggle-payment-gateway-enabled' ), |
| 216 | ), |
| 217 | 'urls' => array( |
| 218 | 'add_product' => Features::is_enabled( 'new-product-management-experience' ) ? esc_url_raw( admin_url( 'admin.php?page=wc-admin&path=/add-product' ) ) : null, |
| 219 | 'import_products' => current_user_can( 'import' ) ? esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_importer' ) ) : null, |
| 220 | 'export_products' => current_user_can( 'export' ) ? esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_exporter' ) ) : null, |
| 221 | ), |
| 222 | ); |
| 223 | |
| 224 | wp_localize_script( 'woocommerce_admin', 'woocommerce_admin', $params ); |
| 225 | } |
| 226 | |
| 227 | // Edit product category pages. |
| 228 | if ( in_array( $screen_id, array( 'edit-product_cat' ) ) ) { |
| 229 | wp_enqueue_media(); |
| 230 | } |
| 231 | |
| 232 | // Products. |
| 233 | if ( in_array( $screen_id, array( 'edit-product' ) ) ) { |
| 234 | wp_enqueue_script( 'woocommerce_quick-edit', WC()->plugin_url() . '/assets/js/admin/quick-edit' . $suffix . '.js', array( 'jquery', 'woocommerce_admin' ), $version ); |
| 235 | |
| 236 | $params = array( |
| 237 | 'strings' => array( |
| 238 | 'allow_reviews' => esc_js( __( 'Enable reviews', 'woocommerce' ) ), |
| 239 | ), |
| 240 | ); |
| 241 | |
| 242 | wp_localize_script( 'woocommerce_quick-edit', 'woocommerce_quick_edit', $params ); |
| 243 | } |
| 244 | |
| 245 | // Product description. |
| 246 | if ( in_array( $screen_id, array( 'product' ), true ) ) { |
| 247 | wp_enqueue_script( 'wc-admin-product-editor', WC()->plugin_url() . '/assets/js/admin/product-editor' . $suffix . '.js', array( 'jquery' ), $version, false ); |
| 248 | |
| 249 | wp_localize_script( |
| 250 | 'wc-admin-product-editor', |
| 251 | 'woocommerce_admin_product_editor', |
| 252 | array( |
| 253 | 'i18n_description' => esc_js( __( 'Product description', 'woocommerce' ) ), |
| 254 | ) |
| 255 | ); |
| 256 | } |
| 257 | |
| 258 | // Meta boxes. |
| 259 | /* phpcs:disable */ |
| 260 | if ( in_array( $screen_id, array( 'product', 'edit-product' ) ) ) { |
| 261 | wp_enqueue_media(); |
| 262 | 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' ), $version ); |
| 263 | 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', 'serializejson', 'media-models', 'backbone', 'jquery-ui-sortable', 'wc-backbone-modal' ), $version ); |
| 264 | |
| 265 | wp_enqueue_script( 'wc-admin-product-meta-boxes' ); |
| 266 | wp_enqueue_script( 'wc-admin-variation-meta-boxes' ); |
| 267 | |
| 268 | $params = array( |
| 269 | 'post_id' => isset( $post->ID ) ? $post->ID : '', |
| 270 | 'plugin_url' => WC()->plugin_url(), |
| 271 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 272 | 'woocommerce_placeholder_img_src' => wc_placeholder_img_src(), |
| 273 | 'add_variation_nonce' => wp_create_nonce( 'add-variation' ), |
| 274 | 'link_variation_nonce' => wp_create_nonce( 'link-variations' ), |
| 275 | 'delete_variations_nonce' => wp_create_nonce( 'delete-variations' ), |
| 276 | 'load_variations_nonce' => wp_create_nonce( 'load-variations' ), |
| 277 | 'save_variations_nonce' => wp_create_nonce( 'save-variations' ), |
| 278 | 'bulk_edit_variations_nonce' => wp_create_nonce( 'bulk-edit-variations' ), |
| 279 | /* translators: %d: Number of variations */ |
| 280 | 'i18n_link_all_variations' => esc_js( sprintf( __( 'Are you sure you want to link 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 ) ), |
| 281 | 'i18n_enter_a_value' => esc_js( __( 'Enter a value', 'woocommerce' ) ), |
| 282 | 'i18n_enter_menu_order' => esc_js( __( 'Variation menu order (determines position in the list of variations)', 'woocommerce' ) ), |
| 283 | 'i18n_enter_a_value_fixed_or_percent' => esc_js( __( 'Enter a value (fixed or %)', 'woocommerce' ) ), |
| 284 | 'i18n_delete_all_variations' => esc_js( __( 'Are you sure you want to delete all variations? This cannot be undone.', 'woocommerce' ) ), |
| 285 | 'i18n_last_warning' => esc_js( __( 'Last warning, are you sure?', 'woocommerce' ) ), |
| 286 | 'i18n_choose_image' => esc_js( __( 'Choose an image', 'woocommerce' ) ), |
| 287 | 'i18n_set_image' => esc_js( __( 'Set variation image', 'woocommerce' ) ), |
| 288 | 'i18n_variation_added' => esc_js( __( 'variation added', 'woocommerce' ) ), |
| 289 | 'i18n_variations_added' => esc_js( __( 'variations added', 'woocommerce' ) ), |
| 290 | 'i18n_no_variations_added' => esc_js( __( 'No variations added', 'woocommerce' ) ), |
| 291 | 'i18n_remove_variation' => esc_js( __( 'Are you sure you want to remove this variation?', 'woocommerce' ) ), |
| 292 | 'i18n_scheduled_sale_start' => esc_js( __( 'Sale start date (YYYY-MM-DD format or leave blank)', 'woocommerce' ) ), |
| 293 | 'i18n_scheduled_sale_end' => esc_js( __( 'Sale end date (YYYY-MM-DD format or leave blank)', 'woocommerce' ) ), |
| 294 | 'i18n_edited_variations' => esc_js( __( 'Save changes before changing page?', 'woocommerce' ) ), |
| 295 | 'i18n_variation_count_single' => esc_js( __( '%qty% variation', 'woocommerce' ) ), |
| 296 | 'i18n_variation_count_plural' => esc_js( __( '%qty% variations', 'woocommerce' ) ), |
| 297 | 'variations_per_page' => absint( apply_filters( 'woocommerce_admin_meta_boxes_variations_per_page', 15 ) ), |
| 298 | ); |
| 299 | |
| 300 | wp_localize_script( 'wc-admin-variation-meta-boxes', 'woocommerce_admin_meta_boxes_variations', $params ); |
| 301 | } |
| 302 | /* phpcs: enable */ |
| 303 | if ( $this->is_order_meta_box_screen( $screen_id ) ) { |
| 304 | $default_location = wc_get_customer_default_location(); |
| 305 | |
| 306 | 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' ), $version ); |
| 307 | wp_localize_script( |
| 308 | 'wc-admin-order-meta-boxes', |
| 309 | 'woocommerce_admin_meta_boxes_order', |
| 310 | array( |
| 311 | 'countries' => wp_json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ), |
| 312 | 'i18n_select_state_text' => esc_attr__( 'Select an option…', 'woocommerce' ), |
| 313 | 'default_country' => isset( $default_location['country'] ) ? $default_location['country'] : '', |
| 314 | 'default_state' => isset( $default_location['state'] ) ? $default_location['state'] : '', |
| 315 | 'placeholder_name' => esc_attr__( 'Name (required)', 'woocommerce' ), |
| 316 | 'placeholder_value' => esc_attr__( 'Value (required)', 'woocommerce' ), |
| 317 | ) |
| 318 | ); |
| 319 | } |
| 320 | /* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */ |
| 321 | if ( in_array( $screen_id, array( 'shop_coupon', 'edit-shop_coupon' ) ) ) { |
| 322 | 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 ); |
| 323 | wp_localize_script( |
| 324 | 'wc-admin-coupon-meta-boxes', |
| 325 | 'woocommerce_admin_meta_boxes_coupon', |
| 326 | array( |
| 327 | 'generate_button_text' => esc_html__( 'Generate coupon code', 'woocommerce' ), |
| 328 | 'characters' => apply_filters( 'woocommerce_coupon_code_generator_characters', 'ABCDEFGHJKMNPQRSTUVWXYZ23456789' ), |
| 329 | 'char_length' => apply_filters( 'woocommerce_coupon_code_generator_character_length', 8 ), |
| 330 | 'prefix' => apply_filters( 'woocommerce_coupon_code_generator_prefix', '' ), |
| 331 | 'suffix' => apply_filters( 'woocommerce_coupon_code_generator_suffix', '' ), |
| 332 | ) |
| 333 | ); |
| 334 | } |
| 335 | /* phpcs: enable */ |
| 336 | if ( in_array( str_replace( 'edit-', '', $screen_id ), array( 'shop_coupon', 'product' ), true ) || $this->is_order_meta_box_screen( $screen_id ) ) { |
| 337 | $post_id = isset( $post->ID ) ? $post->ID : ''; |
| 338 | $currency = ''; |
| 339 | $remove_item_notice = __( 'Are you sure you want to remove the selected items?', 'woocommerce' ); |
| 340 | $remove_fee_notice = __( 'Are you sure you want to remove the selected fees?', 'woocommerce' ); |
| 341 | $remove_shipping_notice = __( 'Are you sure you want to remove the selected shipping?', 'woocommerce' ); |
| 342 | $product = wc_get_product( $post_id ); |
| 343 | |
| 344 | // Eventually this will become wc_data_or_post object as we implement more custom tables. |
| 345 | $order_or_post_object = $post; |
| 346 | if ( ( $theorder instanceof WC_Order ) && $this->is_order_meta_box_screen( $screen_id ) ) { |
| 347 | $order_or_post_object = $theorder; |
| 348 | if ( $order_or_post_object ) { |
| 349 | $currency = $order_or_post_object->get_currency(); |
| 350 | |
| 351 | if ( ! $order_or_post_object->has_status( array( 'pending', 'failed', 'cancelled' ) ) ) { |
| 352 | $remove_item_notice = $remove_item_notice . ' ' . __( "You may need to manually restore the item's stock.", 'woocommerce' ); |
| 353 | } |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | $params = array( |
| 358 | 'remove_item_notice' => $remove_item_notice, |
| 359 | 'remove_fee_notice' => $remove_fee_notice, |
| 360 | 'remove_shipping_notice' => $remove_shipping_notice, |
| 361 | 'i18n_select_items' => __( 'Please select some items.', 'woocommerce' ), |
| 362 | 'i18n_do_refund' => __( 'Are you sure you wish to process this refund? This action cannot be undone.', 'woocommerce' ), |
| 363 | 'i18n_delete_refund' => __( 'Are you sure you wish to delete this refund? This action cannot be undone.', 'woocommerce' ), |
| 364 | 'i18n_delete_tax' => __( 'Are you sure you wish to delete this tax column? This action cannot be undone.', 'woocommerce' ), |
| 365 | 'remove_item_meta' => __( 'Remove this item meta?', 'woocommerce' ), |
| 366 | 'remove_attribute' => __( 'Remove this attribute?', 'woocommerce' ), |
| 367 | 'name_label' => __( 'Name', 'woocommerce' ), |
| 368 | 'remove_label' => __( 'Remove', 'woocommerce' ), |
| 369 | 'click_to_toggle' => __( 'Click to toggle', 'woocommerce' ), |
| 370 | 'values_label' => __( 'Value(s)', 'woocommerce' ), |
| 371 | 'text_attribute_tip' => __( 'Enter some text, or some attributes by pipe (|) separating values.', 'woocommerce' ), |
| 372 | 'visible_label' => __( 'Visible on the product page', 'woocommerce' ), |
| 373 | 'used_for_variations_label' => __( 'Used for variations', 'woocommerce' ), |
| 374 | 'new_attribute_prompt' => __( 'Enter a name for the new attribute term:', 'woocommerce' ), |
| 375 | 'calc_totals' => __( 'Recalculate totals? This will calculate taxes based on the customers country (or the store base country) and update totals.', 'woocommerce' ), |
| 376 | 'copy_billing' => __( 'Copy billing information to shipping information? This will remove any currently entered shipping information.', 'woocommerce' ), |
| 377 | 'load_billing' => __( "Load the customer's billing information? This will remove any currently entered billing information.", 'woocommerce' ), |
| 378 | 'load_shipping' => __( "Load the customer's shipping information? This will remove any currently entered shipping information.", 'woocommerce' ), |
| 379 | 'featured_label' => __( 'Featured', 'woocommerce' ), |
| 380 | 'prices_include_tax' => esc_attr( get_option( 'woocommerce_prices_include_tax' ) ), |
| 381 | 'tax_based_on' => esc_attr( get_option( 'woocommerce_tax_based_on' ) ), |
| 382 | 'round_at_subtotal' => esc_attr( get_option( 'woocommerce_tax_round_at_subtotal' ) ), |
| 383 | 'no_customer_selected' => __( 'No customer selected', 'woocommerce' ), |
| 384 | 'plugin_url' => WC()->plugin_url(), |
| 385 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 386 | 'order_item_nonce' => wp_create_nonce( 'order-item' ), |
| 387 | 'add_attribute_nonce' => wp_create_nonce( 'add-attribute' ), |
| 388 | 'save_attributes_nonce' => wp_create_nonce( 'save-attributes' ), |
| 389 | 'calc_totals_nonce' => wp_create_nonce( 'calc-totals' ), |
| 390 | 'get_customer_details_nonce' => wp_create_nonce( 'get-customer-details' ), |
| 391 | 'search_products_nonce' => wp_create_nonce( 'search-products' ), |
| 392 | 'grant_access_nonce' => wp_create_nonce( 'grant-access' ), |
| 393 | 'revoke_access_nonce' => wp_create_nonce( 'revoke-access' ), |
| 394 | 'add_order_note_nonce' => wp_create_nonce( 'add-order-note' ), |
| 395 | 'delete_order_note_nonce' => wp_create_nonce( 'delete-order-note' ), |
| 396 | 'calendar_image' => WC()->plugin_url() . '/assets/images/calendar.png', |
| 397 | '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, |
| 398 | 'base_country' => WC()->countries->get_base_country(), |
| 399 | 'currency_format_num_decimals' => wc_get_price_decimals(), |
| 400 | 'currency_format_symbol' => get_woocommerce_currency_symbol( $currency ), |
| 401 | 'currency_format_decimal_sep' => esc_attr( wc_get_price_decimal_separator() ), |
| 402 | 'currency_format_thousand_sep' => esc_attr( wc_get_price_thousand_separator() ), |
| 403 | 'currency_format' => esc_attr( str_replace( array( '%1$s', '%2$s' ), array( '%s', '%v' ), get_woocommerce_price_format() ) ), // For accounting JS. |
| 404 | 'rounding_precision' => wc_get_rounding_precision(), |
| 405 | 'tax_rounding_mode' => wc_get_tax_rounding_mode(), |
| 406 | 'product_types' => array_unique( array_merge( array( 'simple', 'grouped', 'variable', 'external' ), array_keys( wc_get_product_types() ) ) ), |
| 407 | 'has_attributes' => ! empty( wc_get_attribute_taxonomies() ) || ! empty( $product ? $product->get_attributes( 'edit' ) : array() ), |
| 408 | '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' ), |
| 409 | 'i18n_permission_revoke' => __( 'Are you sure you want to revoke access to this download?', 'woocommerce' ), |
| 410 | 'i18n_tax_rate_already_exists' => __( 'You cannot add the same tax rate twice!', 'woocommerce' ), |
| 411 | 'i18n_delete_note' => __( 'Are you sure you wish to delete this note? This action cannot be undone.', 'woocommerce' ), |
| 412 | 'i18n_apply_coupon' => __( 'Enter a coupon code to apply. Discounts are applied to line totals, before taxes.', 'woocommerce' ), |
| 413 | 'i18n_add_fee' => __( 'Enter a fixed amount or percentage to apply as a fee.', 'woocommerce' ), |
| 414 | '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' ), |
| 415 | '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' ), |
| 416 | 'i18n_product_external_tip' => __( '<b>External or Affiliate –</b> one that you list and describe on your website but is sold elsewhere.', 'woocommerce' ), |
| 417 | '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' ), |
| 418 | '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' ), |
| 419 | 'i18n_product_description_tip' => __( 'Describe this product. What makes it unique? What are its most important features?', 'woocommerce' ), |
| 420 | 'i18n_product_short_description_tip' => __( 'Summarize this product in 1-2 short sentences. We’ll show it at the top of the page.', 'woocommerce' ), |
| 421 | /* translators: %1$s: maximum file size */ |
| 422 | '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() ) ), |
| 423 | ); |
| 424 | |
| 425 | wp_localize_script( 'wc-admin-meta-boxes', 'woocommerce_admin_meta_boxes', $params ); |
| 426 | } |
| 427 | |
| 428 | // Term ordering - only when sorting by term_order. |
| 429 | /* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */ |
| 430 | 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'] ) ) { |
| 431 | |
| 432 | wp_register_script( 'woocommerce_term_ordering', WC()->plugin_url() . '/assets/js/admin/term-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), $version ); |
| 433 | wp_enqueue_script( 'woocommerce_term_ordering' ); |
| 434 | |
| 435 | $taxonomy = isset( $_GET['taxonomy'] ) ? wc_clean( wp_unslash( $_GET['taxonomy'] ) ) : ''; |
| 436 | |
| 437 | $woocommerce_term_order_params = array( |
| 438 | 'taxonomy' => $taxonomy, |
| 439 | ); |
| 440 | |
| 441 | wp_localize_script( 'woocommerce_term_ordering', 'woocommerce_term_ordering_params', $woocommerce_term_order_params ); |
| 442 | } |
| 443 | /* phpcs: enable */ |
| 444 | |
| 445 | // Product sorting - only when sorting by menu order on the products page. |
| 446 | if ( current_user_can( 'edit_others_pages' ) && 'edit-product' === $screen_id && isset( $wp_query->query['orderby'] ) && 'menu_order title' === $wp_query->query['orderby'] ) { |
| 447 | wp_register_script( 'woocommerce_product_ordering', WC()->plugin_url() . '/assets/js/admin/product-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), $version, true ); |
| 448 | wp_enqueue_script( 'woocommerce_product_ordering' ); |
| 449 | } |
| 450 | |
| 451 | // Reports Pages. |
| 452 | /* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */ |
| 453 | if ( in_array( $screen_id, apply_filters( 'woocommerce_reports_screen_ids', array( $wc_screen_id . '_page_wc-reports', 'toplevel_page_wc-reports', 'dashboard' ) ) ) ) { |
| 454 | wp_register_script( 'wc-reports', WC()->plugin_url() . '/assets/js/admin/reports' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker' ), $version ); |
| 455 | |
| 456 | wp_enqueue_script( 'wc-reports' ); |
| 457 | wp_enqueue_script( 'flot' ); |
| 458 | wp_enqueue_script( 'flot-resize' ); |
| 459 | wp_enqueue_script( 'flot-time' ); |
| 460 | wp_enqueue_script( 'flot-pie' ); |
| 461 | wp_enqueue_script( 'flot-stack' ); |
| 462 | } |
| 463 | /* phpcs: enable */ |
| 464 | |
| 465 | // API settings. |
| 466 | if ( $wc_screen_id . '_page_wc-settings' === $screen_id && isset( $_GET['section'] ) && 'keys' == $_GET['section'] ) { |
| 467 | wp_register_script( 'wc-api-keys', WC()->plugin_url() . '/assets/js/admin/api-keys' . $suffix . '.js', array( 'jquery', 'woocommerce_admin', 'underscore', 'backbone', 'wp-util', 'qrcode', 'wc-clipboard' ), $version, true ); |
| 468 | wp_enqueue_script( 'wc-api-keys' ); |
| 469 | wp_localize_script( |
| 470 | 'wc-api-keys', |
| 471 | 'woocommerce_admin_api_keys', |
| 472 | array( |
| 473 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 474 | 'update_api_nonce' => wp_create_nonce( 'update-api-key' ), |
| 475 | 'clipboard_failed' => esc_html__( 'Copying to clipboard failed. Please press Ctrl/Cmd+C to copy.', 'woocommerce' ), |
| 476 | ) |
| 477 | ); |
| 478 | } |
| 479 | |
| 480 | // System status. |
| 481 | if ( $wc_screen_id . '_page_wc-status' === $screen_id ) { |
| 482 | wp_register_script( 'wc-admin-system-status', WC()->plugin_url() . '/assets/js/admin/system-status' . $suffix . '.js', array( 'wc-clipboard' ), $version ); |
| 483 | wp_enqueue_script( 'wc-admin-system-status' ); |
| 484 | wp_localize_script( |
| 485 | 'wc-admin-system-status', |
| 486 | 'woocommerce_admin_system_status', |
| 487 | array( |
| 488 | 'delete_log_confirmation' => esc_js( __( 'Are you sure you want to delete this log?', 'woocommerce' ) ), |
| 489 | 'run_tool_confirmation' => esc_js( __( 'Are you sure you want to run this tool?', 'woocommerce' ) ), |
| 490 | ) |
| 491 | ); |
| 492 | } |
| 493 | |
| 494 | if ( in_array( $screen_id, array( 'user-edit', 'profile' ) ) ) { |
| 495 | wp_register_script( 'wc-users', WC()->plugin_url() . '/assets/js/admin/users' . $suffix . '.js', array( 'jquery', 'wc-enhanced-select', 'selectWoo' ), $version, true ); |
| 496 | wp_enqueue_script( 'wc-users' ); |
| 497 | wp_localize_script( |
| 498 | 'wc-users', |
| 499 | 'wc_users_params', |
| 500 | array( |
| 501 | 'countries' => wp_json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ), |
| 502 | 'i18n_select_state_text' => esc_attr__( 'Select an option…', 'woocommerce' ), |
| 503 | ) |
| 504 | ); |
| 505 | } |
| 506 | |
| 507 | if ( WC_Marketplace_Suggestions::show_suggestions_for_screen( $screen_id ) ) { |
| 508 | $active_plugin_slugs = array_map( 'dirname', get_option( 'active_plugins' ) ); |
| 509 | wp_register_script( |
| 510 | 'marketplace-suggestions', |
| 511 | WC()->plugin_url() . '/assets/js/admin/marketplace-suggestions' . $suffix . '.js', |
| 512 | array( 'jquery', 'underscore', 'js-cookie' ), |
| 513 | $version, |
| 514 | true |
| 515 | ); |
| 516 | wp_localize_script( |
| 517 | 'marketplace-suggestions', |
| 518 | 'marketplace_suggestions', |
| 519 | array( |
| 520 | 'dismiss_suggestion_nonce' => wp_create_nonce( 'add_dismissed_marketplace_suggestion' ), |
| 521 | 'active_plugins' => $active_plugin_slugs, |
| 522 | 'dismissed_suggestions' => WC_Marketplace_Suggestions::get_dismissed_suggestions(), |
| 523 | 'suggestions_data' => WC_Marketplace_Suggestions::get_suggestions_api_data(), |
| 524 | 'manage_suggestions_url' => admin_url( 'admin.php?page=wc-settings&tab=advanced§ion=woocommerce_com' ), |
| 525 | 'in_app_purchase_params' => WC_Admin_Addons::get_in_app_purchase_url_params(), |
| 526 | 'i18n_marketplace_suggestions_default_cta' |
| 527 | => esc_html__( 'Learn More', 'woocommerce' ), |
| 528 | 'i18n_marketplace_suggestions_dismiss_tooltip' |
| 529 | => esc_attr__( 'Dismiss this suggestion', 'woocommerce' ), |
| 530 | 'i18n_marketplace_suggestions_manage_suggestions' |
| 531 | => esc_html__( 'Manage suggestions', 'woocommerce' ), |
| 532 | ) |
| 533 | ); |
| 534 | wp_enqueue_script( 'marketplace-suggestions' ); |
| 535 | } |
| 536 | |
| 537 | } |
| 538 | |
| 539 | /** |
| 540 | * Helper function to determine whether the current screen is an order edit screen. |
| 541 | * |
| 542 | * @param string $screen_id Screen ID. |
| 543 | * |
| 544 | * @return bool Whether the current screen is an order edit screen. |
| 545 | */ |
| 546 | private function is_order_meta_box_screen( $screen_id ) { |
| 547 | $screen_id = str_replace( 'edit-', '', $screen_id ); |
| 548 | |
| 549 | $types_with_metaboxes_screen_ids = array_filter( |
| 550 | array_map( |
| 551 | 'wc_get_page_screen_id', |
| 552 | wc_get_order_types( 'order-meta-boxes' ) |
| 553 | ) |
| 554 | ); |
| 555 | |
| 556 | return in_array( $screen_id, $types_with_metaboxes_screen_ids, true ); |
| 557 | } |
| 558 | |
| 559 | } |
| 560 | |
| 561 | endif; |
| 562 | |
| 563 | return new WC_Admin_Assets(); |
| 564 |