Changeset 1427953
- Timestamp:
- 06/01/2016 12:11:28 AM (10 years ago)
- Location:
- woocommerce-product-sku-generator/trunk
- Files:
-
- 4 edited
-
i18n/languages/woocommerce-product-sku-generator.pot (modified) (4 diffs)
-
readme.txt (modified) (7 diffs)
-
screenshots/screenshot-1.png (modified) (previous)
-
woocommerce-product-sku-generator.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
woocommerce-product-sku-generator/trunk/i18n/languages/woocommerce-product-sku-generator.pot
r1330720 r1427953 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: WooCommerce Product SKU Generator 2. 1.0\n"5 "Project-Id-Version: WooCommerce Product SKU Generator 2.2.0\n" 6 6 "Report-Msgid-Bugs-To: " 7 7 "https://github.com/skyverge/woocommerce-product-sku-generator/issues\n" … … 14 14 "Language-Team: LANGUAGE <[email protected]>\n" 15 15 16 #: build/woocommerce-product-sku-generator.php:41 17 #: woocommerce-product-sku-generator.php:41 16 #: build/woocommerce-product-sku-generator.php:121 17 #: woocommerce-product-sku-generator.php:121 18 #. translators: Placeholders: %s - plugin name 19 msgid "You cannot clone instances of %s." 20 msgstr "" 21 22 #: build/woocommerce-product-sku-generator.php:133 23 #: woocommerce-product-sku-generator.php:133 24 #. translators: Placeholders: %s - plugin name 25 msgid "You cannot unserialize instances of %s." 26 msgstr "" 27 28 #: build/woocommerce-product-sku-generator.php:147 29 #: woocommerce-product-sku-generator.php:147 30 msgid "Configure" 31 msgstr "" 32 33 #: build/woocommerce-product-sku-generator.php:148 34 #: woocommerce-product-sku-generator.php:148 35 msgid "FAQ" 36 msgstr "" 37 38 #: build/woocommerce-product-sku-generator.php:149 39 #: woocommerce-product-sku-generator.php:149 40 msgid "Support" 41 msgstr "" 42 43 #: build/woocommerce-product-sku-generator.php:194 44 #: woocommerce-product-sku-generator.php:194 18 45 #. translators: %1$s and %2$s are <strong> tags. %3$s and %4$s are <a> tags 19 46 msgid "" 20 47 "%1$sWooCommerce Product SKU Generator is inactive.%2$s This plugin requires " 21 "WooCommerce 2. 2 or newer. Please %3$supdate WooCommerce to version 2.2or "48 "WooCommerce 2.3 or newer. Please %3$supdate WooCommerce to version 2.3 or " 22 49 "newer%4$s" 23 50 msgstr "" 24 51 25 #: build/woocommerce-product-sku-generator.php:141 26 #: woocommerce-product-sku-generator.php:137 27 msgid "Configure" 28 msgstr "" 29 30 #: build/woocommerce-product-sku-generator.php:142 31 #: woocommerce-product-sku-generator.php:138 32 msgid "Support" 33 msgstr "" 34 35 #: build/woocommerce-product-sku-generator.php:283 36 #: woocommerce-product-sku-generator.php:279 52 #: build/woocommerce-product-sku-generator.php:339 53 #: woocommerce-product-sku-generator.php:339 37 54 msgid "SKU" 38 55 msgstr "" 39 56 40 #: build/woocommerce-product-sku-generator.php:3 5541 #: woocommerce-product-sku-generator.php:3 2957 #: build/woocommerce-product-sku-generator.php:387 58 #: woocommerce-product-sku-generator.php:387 42 59 msgid "Product SKUs" 43 60 msgstr "" 44 61 45 #: build/woocommerce-product-sku-generator.php:3 6146 #: woocommerce-product-sku-generator.php:3 3562 #: build/woocommerce-product-sku-generator.php:393 63 #: woocommerce-product-sku-generator.php:393 47 64 msgid "Generate Simple / Parent SKUs:" 48 65 msgstr "" 49 66 50 #: build/woocommerce-product-sku-generator.php:3 6251 #: woocommerce-product-sku-generator.php:3 3667 #: build/woocommerce-product-sku-generator.php:394 68 #: woocommerce-product-sku-generator.php:394 52 69 msgid "" 53 70 "Generating simple / parent SKUs disables the SKU field while editing " … … 55 72 msgstr "" 56 73 57 #: build/woocommerce-product-sku-generator.php:3 6658 #: build/woocommerce-product-sku-generator.php: 38259 #: woocommerce-product-sku-generator.php:3 4060 #: woocommerce-product-sku-generator.php: 35674 #: build/woocommerce-product-sku-generator.php:398 75 #: build/woocommerce-product-sku-generator.php:414 76 #: woocommerce-product-sku-generator.php:398 77 #: woocommerce-product-sku-generator.php:414 61 78 msgid "Never (let me set them)" 62 79 msgstr "" 63 80 64 #: build/woocommerce-product-sku-generator.php:3 6765 #: woocommerce-product-sku-generator.php:3 4181 #: build/woocommerce-product-sku-generator.php:399 82 #: woocommerce-product-sku-generator.php:399 66 83 msgid "Using the product slug (name)" 67 84 msgstr "" 68 85 69 #: build/woocommerce-product-sku-generator.php: 36870 #: woocommerce-product-sku-generator.php: 34286 #: build/woocommerce-product-sku-generator.php:400 87 #: woocommerce-product-sku-generator.php:400 71 88 msgid "Using the product ID" 72 89 msgstr "" 73 90 74 #: build/woocommerce-product-sku-generator.php: 37375 #: woocommerce-product-sku-generator.php: 34791 #: build/woocommerce-product-sku-generator.php:405 92 #: woocommerce-product-sku-generator.php:405 76 93 msgid "" 77 94 "Determine how SKUs for simple, external, or parent products will be " … … 79 96 msgstr "" 80 97 81 #: build/woocommerce-product-sku-generator.php: 37782 #: woocommerce-product-sku-generator.php: 35198 #: build/woocommerce-product-sku-generator.php:409 99 #: woocommerce-product-sku-generator.php:409 83 100 msgid "Generate Variation SKUs:" 84 101 msgstr "" 85 102 86 #: build/woocommerce-product-sku-generator.php: 37887 #: woocommerce-product-sku-generator.php: 352103 #: build/woocommerce-product-sku-generator.php:410 104 #: woocommerce-product-sku-generator.php:410 88 105 msgid "Determine how SKUs for product variations will be generated." 89 106 msgstr "" 90 107 91 #: build/woocommerce-product-sku-generator.php: 38392 #: woocommerce-product-sku-generator.php: 357108 #: build/woocommerce-product-sku-generator.php:415 109 #: woocommerce-product-sku-generator.php:415 93 110 msgid "Using the attribute slugs (names)" 94 111 msgstr "" 95 112 96 #: build/woocommerce-product-sku-generator.php: 38497 #: woocommerce-product-sku-generator.php: 358113 #: build/woocommerce-product-sku-generator.php:416 114 #: woocommerce-product-sku-generator.php:416 98 115 msgid "Using the variation ID" 99 116 msgstr "" 100 117 101 #: build/woocommerce-product-sku-generator.php: 393102 #: woocommerce-product-sku-generator.php: 367103 msgid "Replace spaces in attributes "118 #: build/woocommerce-product-sku-generator.php:425 119 #: woocommerce-product-sku-generator.php:425 120 msgid "Replace spaces in attributes?" 104 121 msgstr "" 105 122 106 #: build/woocommerce-product-sku-generator.php: 395107 #: woocommerce-product-sku-generator.php: 369123 #: build/woocommerce-product-sku-generator.php:427 124 #: woocommerce-product-sku-generator.php:427 108 125 #. translators: placeholders are <strong> tags 109 126 msgid "" 110 "Replace spaces in attribute names with underscores.%1$sWill update existing " 111 "variation SKUs when product is saved%2$s." 127 "%1$sWill update existing variation SKUs when product is saved if they " 128 "contain spaces%2$s." 129 msgstr "" 130 131 #: build/woocommerce-product-sku-generator.php:431 132 #: woocommerce-product-sku-generator.php:431 133 msgid "Do not replace spaces in attribute names." 134 msgstr "" 135 136 #: build/woocommerce-product-sku-generator.php:432 137 #: woocommerce-product-sku-generator.php:432 138 msgid "Replace spaces with underscores" 139 msgstr "" 140 141 #: build/woocommerce-product-sku-generator.php:433 142 #: woocommerce-product-sku-generator.php:433 143 msgid "Replace spaces with dashes / hyphens" 144 msgstr "" 145 146 #: build/woocommerce-product-sku-generator.php:438 147 #: woocommerce-product-sku-generator.php:438 148 msgid "Replace spaces in attribute names when used in a SKU." 112 149 msgstr "" 113 150 -
woocommerce-product-sku-generator/trunk/readme.txt
r1330720 r1427953 3 3 Tags: woocommerce, sku, product sku 4 4 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&[email protected]&item_name=Donation+for+WooCommerce+SKU+Generator 5 Requires at least: 3.86 Tested up to: 4. 4.17 Requires WooCommerce at least: 2. 28 Tested WooCommerce up to: 2. 59 Stable Tag: 2. 1.05 Requires at least: 4.0 6 Tested up to: 4.5.2 7 Requires WooCommerce at least: 2.3 8 Tested WooCommerce up to: 2.6 9 Stable Tag: 2.2.0 10 10 License: GPLv3 11 11 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 15 15 == Description == 16 16 17 > **Requires: WooCommerce 2. 2** or newer17 > **Requires: WooCommerce 2.3** or newer 18 18 19 19 Automatically generate a SKU for parent / simple products, variations, or both when the product is published or updated. … … 67 67 > **NOTE that** any time a product is updated, its SKU will be generated, so this may override old SKUs if you update products. This plugin is meant for complete SKU automation, or you can selectively enable / disable it as needed. 68 68 69 1. Be sure you're running WooCommerce 2.2+ in your shop. 70 2. You can: (1) upload the entire `woocommerce-product-sku-generator` folder to the `/wp-content/plugins/` directory, (2) upload the .zip file with the plugin under **Plugins > Add New > Upload**, or (3) Search for "WooCommerce Product SKU Generator" under Plugins > Add New 71 3. Activate the plugin through the **Plugins** menu in WordPress 72 4. Click the "Configure" plugin link or go to **WooCommerce > Settings > Products** and scroll down to the "Product SKUs". Select which SKUs you'd like to generate and what should be used to generate them. 73 5. If you generate variation SKUs with slugs, determine if spaces in attribute names should be replaced with underscores instead. 74 6. View [documentation on the product page](http://www.skyverge.com/product/woocommerce-product-sku-generator/) for more help if needed. 69 1. Be sure you're running WooCommerce 2.3+ in your shop. 70 71 2. You can: 72 73 - upload the entire `woocommerce-product-sku-generator` folder to the `/wp-content/plugins/` directory, 74 - upload the .zip file with the plugin under **Plugins > Add New > Upload**, or 75 - Search for "WooCommerce Product SKU Generator" under Plugins > Add New 76 77 3. Activate the plugin through the **Plugins** menu in WordPress 78 79 4. Click the "Configure" plugin link or go to **WooCommerce > Settings > Products** and scroll down to the "Product SKUs". Select which SKUs you'd like to generate and what should be used to generate them. 80 81 5. If you generate variation SKUs with slugs, determine if spaces in attribute names should be replaced with underscores instead. 82 83 6. View [documentation on the product page](http://www.skyverge.com/product/woocommerce-product-sku-generator/) for more help if needed. 75 84 76 85 == Frequently Asked Questions == … … 90 99 Variation SKUs can be set manually if you're _not_ generating them. **They will be overridden** if your settings are set auto-generate them, even if you try to change them manually. Please check your settings here. 91 100 92 If you'd like to change an SKU for a product, disable the plugin, change the SKU, and update the product. You can re-enable the plugin as needed. 101 If you'd like to change a SKU for a product, disable the plugin, change the SKU, and update the product. You can re-enable the plugin as needed. 102 103 = I'm using IDs for SKUs. Will they be sequential? = 104 105 Roughly, yes. Actually, no. The SKUs will increase as you add more products / variations, but these use the post ID from WordPress (similar to your orders). Each SKU will be higher than the last, but they won't be exactly in order, as other posts (like blog posts, orders or products), also use the same ID counter. Your SKUs will increase, but skip numbers. 93 106 94 107 = Can I use something other than the product slug to generate the SKUs? = … … 96 109 Yep! Version 2.0 added the ability to use product slugs or IDs. 97 110 98 For more advanced uses, you can use the `wc_sku_generator_sku` filter (v1.2.2+), which passes the parent SKU as the value and the product as a variable, to change what's used as the parent SKU. You can change the variation SKU using the `wc_sku_generator_variation_sku` filter (v2.0.0+).111 For more advanced uses, you can use the `wc_sku_generator_sku` filter, which passes the parent SKU as the value and the product as a variable, to change what's used as the parent SKU. You can change the variation SKU using the `wc_sku_generator_variation_sku` filter. 99 112 100 113 You **must** use a unique value for SKUs (WooCommerce checks this). For example, you could generate a unique string or number in a custom snippet to use for the SKU with the help of a developer. 101 102 = I'm using IDs for SKUs. Will they be sequential? =103 104 Roughly, yes. Actually, no. The SKUs will increase as you add more products / variations, but these use the post ID from WordPress (similar to your orders). Each SKU will be higher than the last, but they won't be exactly in order, as other posts (like blog posts, orders or products), also use the same ID counter. Your SKUs will increase, but skip numbers.105 114 106 115 = Sometimes attributes for my variation SKUs aren't in the same order. Can I fix this? = … … 130 139 By default, if you have an attribute name with a space (such as "Burnt Marshmallow" for color), the SKU will use this exact formatting. A SKU for this variation would look like: `parentSKU-Burnt Marshmallow` 131 140 132 If you enable the setting to replace spaces, this will instead look like: `parentSKU-Burnt_Marshmallow` -- this is helpful if your external fulfillment service does not allow spaces in SKUs.141 If you enable the setting to replace spaces, this will instead look like: `parentSKU-Burnt_Marshmallow` or `parentSKU-Burnt-Marshmallow` -- depending on which setting you've chose. This is helpful if your external fulfillment service does not allow spaces in SKUs. 133 142 134 143 = Attribute Sorting = … … 147 156 148 157 == Changelog == 158 159 = 2016.05.31 - version 2.2.0 = 160 * Feature: attribute names can now replace spaces with hyphens in addition to underscores 161 * Misc: added support for WooCommerce 2.6 162 * Misc: removed support for WooCommerce 2.2 149 163 150 164 = 2016.01.18 - version 2.1.0 = -
woocommerce-product-sku-generator/trunk/woocommerce-product-sku-generator.php
r1330720 r1427953 6 6 * Author: SkyVerge 7 7 * Author URI: http://www.skyverge.com/ 8 * Version: 2. 1.08 * Version: 2.2.0 9 9 * Text Domain: woocommerce-product-sku-generator 10 10 * Domain Path: /i18n/languages/ … … 24 24 25 25 26 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly 26 defined( 'ABSPATH' ) or exit; 27 27 28 28 29 29 // Check if WooCommerce is active 30 if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) )30 if ( ! WC_SKU_Generator::is_woocommerce_active() ) { 31 31 return; 32 } 32 33 33 34 34 35 // WC version check 35 if ( version_compare( get_option( 'woocommerce_db_version' ), '2.2.0', '<' ) ) { 36 37 function wc_sku_generator_outdated_version_notice() { 36 if ( version_compare( get_option( 'woocommerce_db_version' ), '2.3.0', '<' ) ) { 37 add_action( 'admin_notices', WC_SKU_Generator::render_outdated_wc_version_notice() ); 38 return; 39 } 40 41 42 // Make sure we're loaded after WC and fire it up! 43 function init_wc_sku_generator() { 44 wc_sku_generator(); 45 } 46 add_action( 'plugins_loaded', 'init_wc_sku_generator' ); 47 48 49 /** 50 * Plugin Description 51 * 52 * Generate a SKU for products that is equal to the product slug or product ID. 53 * Simple / parent products can have a SKU equal to the slug or ID. 54 * Variable products can have a SKU that combines the parent SKU + variation ID or attributes 55 */ 56 57 class WC_SKU_Generator { 58 59 60 const VERSION = '2.2.0'; 61 62 63 /** @var WC_SKU_Generator single instance of this plugin */ 64 protected static $instance; 65 66 67 public function __construct() { 68 69 // load translations 70 add_action( 'init', array( $this, 'load_translation' ) ); 71 72 if ( is_admin() && ! is_ajax() ) { 73 74 // add settings 75 add_filter( 'woocommerce_products_general_settings', array( $this, 'add_settings' ) ); 76 add_filter( 'woocommerce_product_settings', array( $this, 'add_settings' ) ); 77 add_action( 'admin_print_scripts', array( $this, 'admin_js' ) ); 78 79 // add plugin links 80 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_plugin_links' ) ); 81 82 // save the generated SKUs during product edit / bulk edit 83 add_action( 'woocommerce_product_bulk_edit_save', array( $this, 'maybe_save_sku' ) ); 84 add_action( 'woocommerce_process_product_meta', array( $this, 'maybe_save_sku' ), 100, 2 ); 85 86 // disable SKU fields when being generated by us 87 add_action( 'init', array( $this, 'maybe_disable_skus' ) ); 88 89 // run every time 90 $this->install(); 91 } 92 } 93 94 95 /** Helper methods ***************************************/ 96 97 98 /** 99 * Main Sku Generator Instance, ensures only one instance is/can be loaded 100 * 101 * @since 2.0.0 102 * @see wc_sku_generator() 103 * @return WC_SKU_Generator 104 */ 105 public static function instance() { 106 if ( is_null( self::$instance ) ) { 107 self::$instance = new self(); 108 } 109 return self::$instance; 110 } 111 112 113 /** 114 * Cloning instances is forbidden due to singleton pattern. 115 * 116 * @since 2.2.0 117 */ 118 public function __clone() { 119 120 /* translators: Placeholders: %s - plugin name */ 121 _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'You cannot clone instances of %s.', 'woocommerce-product-sku-generator' ), 'WooCommerce Product SKU Generator' ), '2.2.0' ); 122 } 123 124 125 /** 126 * Unserializing instances is forbidden due to singleton pattern. 127 * 128 * @since 2.2.0 129 */ 130 public function __wakeup() { 131 132 /* translators: Placeholders: %s - plugin name */ 133 _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'You cannot unserialize instances of %s.', 'woocommerce-product-sku-generator' ), 'WooCommerce Product SKU Generator' ), '2.2.0' ); 134 } 135 136 137 /** 138 * Adds plugin page links 139 * 140 * @since 2.0.0 141 * @param array $links all plugin links 142 * @return array $links all plugin links + our custom links (i.e., "Settings") 143 */ 144 public function add_plugin_links( $links ) { 145 146 $plugin_links = array( 147 '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=products' ) . '">' . __( 'Configure', 'woocommerce-product-sku-generator' ) . '</a>', 148 '<a href="https://wordpress.org/plugins/woocommerce-product-sku-generator/faq/">' . __( 'FAQ', 'woocommerce-product-sku-generator' ) . '</a>', 149 '<a href="https://wordpress.org/support/plugin/woocommerce-product-sku-generator">' . __( 'Support', 'woocommerce-product-sku-generator' ) . '</a>', 150 ); 151 152 return array_merge( $plugin_links, $links ); 153 } 154 155 156 /** 157 * Load Translations 158 * 159 * @since 1.2.1 160 */ 161 public function load_translation() { 162 // localization 163 load_plugin_textdomain( 'woocommerce-product-sku-generator', false, dirname( plugin_basename( __FILE__ ) ) . '/i18n/languages' ); 164 } 165 166 167 /** 168 * Checks if WooCommerce is active 169 * 170 * @since 2.2.0 171 * @return bool true if WooCommerce is active, false otherwise 172 */ 173 public static function is_woocommerce_active() { 174 175 $active_plugins = (array) get_option( 'active_plugins', array() ); 176 177 if ( is_multisite() ) { 178 $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); 179 } 180 181 return in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); 182 } 183 184 185 /** 186 * Renders a notice when WooCommerce version is outdated 187 * 188 * @since 2.2.0 189 */ 190 public static function render_outdated_wc_version_notice() { 38 191 39 192 $message = sprintf( 40 /* translators: %1$s and %2$s are <strong> tags. %3$s and %4$s are <a> tags */41 esc_html__( '%1$sWooCommerce Product SKU Generator is inactive.%2$s This plugin requires WooCommerce 2. 2 or newer. Please %3$supdate WooCommerce to version 2.2or newer%4$s', 'woocommerce-product-sku-generator' ),193 /* translators: %1$s and %2$s are <strong> tags. %3$s and %4$s are <a> tags */ 194 esc_html__( '%1$sWooCommerce Product SKU Generator is inactive.%2$s This plugin requires WooCommerce 2.3 or newer. Please %3$supdate WooCommerce to version 2.3 or newer%4$s', 'woocommerce-product-sku-generator' ), 42 195 '<strong>', 43 196 '</strong>', … … 46 199 ); 47 200 48 echo sprintf( '<div class="error"><p>%s</p></div>', $message ); 49 } 50 51 add_action( 'admin_notices', 'wc_sku_generator_outdated_version_notice' ); 52 53 return; 54 } 55 56 57 // Make sure we're loaded after WC 58 function init_wc_sku_generator() { 59 // Fire it up! 60 wc_sku_generator(); 61 } 62 add_action( 'plugins_loaded', 'init_wc_sku_generator' ); 63 64 65 /** 66 * Plugin Description 67 * 68 * Generate a SKU for products that is equal to the product slug or product ID. 69 * Simple / parent products will have one SKU equal to the slug or ID. 70 * Variable products 71 */ 72 73 74 class WC_SKU_Generator { 75 76 77 const VERSION = '2.1.0'; 78 79 80 /** @var WC_SKU_Generator single instance of this plugin */ 81 protected static $instance; 82 83 84 public function __construct() { 85 86 // load translations 87 add_action( 'init', array( $this, 'load_translation' ) ); 88 89 if ( is_admin() && ! is_ajax() ) { 90 91 // add settings 92 add_filter( 'woocommerce_products_general_settings', array( $this, 'add_settings' ) ); 93 add_filter( 'woocommerce_product_settings', array( $this, 'add_settings' ) ); 94 add_action( 'admin_print_scripts', array( $this, 'admin_js' ) ); 95 96 // add plugin links 97 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_plugin_links' ) ); 98 99 // save the generated SKUs during product edit / bulk edit 100 add_action( 'woocommerce_product_bulk_edit_save', array( $this, 'maybe_save_sku' ) ); 101 add_action( 'woocommerce_process_product_meta', array( $this, 'maybe_save_sku' ), 100, 2 ); 102 103 // disable SKU fields when being generated by us 104 add_action( 'init', array( $this, 'maybe_disable_skus' ) ); 105 106 // run every time 107 $this->install(); 108 } 109 } 110 111 112 /** 113 * Main Sku Generator Instance, ensures only one instance is/can be loaded 114 * 115 * @since 2.0.0 116 * @see wc_sku_generator() 117 * @return WC_SKU_Generator 118 */ 119 public static function instance() { 120 if ( is_null( self::$instance ) ) { 121 self::$instance = new self(); 122 } 123 return self::$instance; 124 } 125 126 127 /** 128 * Adds plugin page links 129 * 130 * @since 2.0.0 131 * @param array $links all plugin links 132 * @return array $links all plugin links + our custom links (i.e., "Settings") 133 */ 134 public function add_plugin_links( $links ) { 135 136 $plugin_links = array( 137 '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=products' ) . '">' . __( 'Configure', 'woocommerce-product-sku-generator' ) . '</a>', 138 '<a href="https://wordpress.org/support/plugin/woocommerce-product-sku-generator">' . __( 'Support', 'woocommerce-product-sku-generator' ) . '</a>', 139 ); 140 141 return array_merge( $plugin_links, $links ); 142 } 143 144 145 /** 146 * Load Translations 147 * 148 * @since 1.2.1 149 */ 150 public function load_translation() { 151 // localization 152 load_plugin_textdomain( 'woocommerce-product-sku-generator', false, dirname( plugin_basename( __FILE__ ) ) . '/i18n/languages' ); 153 } 201 printf( '<div class="error"><p>%s</p></div>', $message ); 202 } 203 204 205 /** Plugin methods ***************************************/ 154 206 155 207 … … 189 241 if ( 'slugs' === get_option( 'wc_sku_generator_variation' ) ) { 190 242 191 // replace spaces in attributes with underscores if set 192 if ( 'yes' === get_option( 'wc_sku_generator_attribute_spaces' ) ) { 193 $variation['attributes'] = str_replace( ' ', '_', $variation['attributes'] ); 243 // replace spaces in attributes depending on settings 244 switch ( get_option( 'wc_sku_generator_attribute_spaces' ) ) { 245 246 case 'underscore': 247 $variation['attributes'] = str_replace( ' ', '_', $variation['attributes'] ); 248 break; 249 250 case 'dash': 251 $variation['attributes'] = str_replace( ' ', '-', $variation['attributes'] ); 252 break; 253 194 254 } 195 255 … … 301 361 $updated_settings = array(); 302 362 303 $setting_id = version_compare( WC_VERSION, '2.3', '>=' ) ? 'product_measurement_options' : 'product_data_options';304 305 363 foreach ( $settings as $setting ) { 306 364 307 365 $updated_settings[] = $setting; 308 366 309 if ( isset( $setting['id'] ) && $setting_id=== $setting['id'] && 'sectionend' === $setting['type'] ) {367 if ( isset( $setting['id'] ) && 'product_measurement_options' === $setting['id'] && 'sectionend' === $setting['type'] ) { 310 368 311 369 $updated_settings = array_merge( $updated_settings, $this->get_settings() ); … … 365 423 366 424 array( 367 'title' => __( 'Replace spaces in attributes', 'woocommerce-product-sku-generator' ),425 'title' => __( 'Replace spaces in attributes?', 'woocommerce-product-sku-generator' ), 368 426 /* translators: placeholders are <strong> tags */ 369 'desc' => sprintf( __( 'Replace spaces in attribute names with underscores.%1$sWill update existing variation SKUs when product is saved%2$s.', 'woocommerce-product-sku-generator' ), '<br /><strong>', '</strong>' ), 370 'id' => 'wc_sku_generator_attribute_spaces', 371 'type' => 'checkbox', 372 'default' => 'no', 427 'desc' => sprintf( __( '%1$sWill update existing variation SKUs when product is saved if they contain spaces%2$s.', 'woocommerce-product-sku-generator' ), '<strong>', '</strong>' ), 428 'id' => 'wc_sku_generator_attribute_spaces', 429 'type' => 'select', 430 'options' => array( 431 'no' => __( 'Do not replace spaces in attribute names.', 'woocommerce-product-sku-generator' ), 432 'underscore' => __( 'Replace spaces with underscores', 'woocommerce-product-sku-generator' ), 433 'dash' => __( 'Replace spaces with dashes / hyphens', 'woocommerce-product-sku-generator' ), 434 ), 435 'default' => 'no', 436 'class' => 'wc-enhanced-select chosen_select', 437 'css' => 'min-width:300px;', 438 'desc_tip' => __( 'Replace spaces in attribute names when used in a SKU.', 'woocommerce-product-sku-generator' ), 373 439 ), 374 440 … … 414 480 415 481 482 /** Lifecycle methods ***************************************/ 483 484 416 485 /** 417 486 * Run every time. Used since the activation hook is not executed when updating a plugin … … 475 544 // Delete the old option now that we've upgraded 476 545 delete_option( 'wc_sku_generator_select' ); 546 } 547 548 // Upgrade to version 2.2.0, this setting was only available in 2.1.0 549 if ( '2.1.0' === $installed_version ) { 550 551 if ( 'yes' === get_option( 'wc_sku_generator_attribute_spaces' ) ) { 552 update_option( 'wc_sku_generator_attribute_spaces', 'underscore' ); 553 } 477 554 } 478 555
Note: See TracChangeset
for help on using the changeset viewer.