Changeset 1657910
- Timestamp:
- 05/15/2017 05:52:12 PM (9 years ago)
- Location:
- colored-order-notes-for-woocommerce/trunk
- Files:
-
- 4 added
- 3 edited
-
assets (added)
-
assets/banner-772x250.jpg (added)
-
assets/icon-128x128.png (added)
-
assets/screenshot-1.png (added)
-
readme.md (modified) (4 diffs)
-
readme.txt (modified) (3 diffs)
-
woocommerce-colored-order-notes.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
colored-order-notes-for-woocommerce/trunk/readme.md
r1489623 r1657910 3 3 **Tags:** woocommerce custom order note color, order note color, colored order note, coloured order notes, woocommerce coloured order notes 4 4 **Requires at least:** WordPress 4.4 or above 5 **Tested up to:** 4. 66 **Stable tag:** 1.0 5 **Tested up to:** 4.7.4 6 **Stable tag:** 1.0.1 7 7 **License:** GPLv3 8 8 **License URI:** http://www.gnu.org/licenses/gpl-3.0.html … … 14 14 WooCommerce Colored Order Notes plugin allows you to to customize order note color for each order status. The plugin is made to work with WooCommerce version 2.5 or higher. Upon activating the plugin you will see "Order Note Colors" tab under "WooCommerce > Settings". 15 15 16 **Note** 17 This plugin works only with English (en_US) locale currently. 16 18 17 19 **Important Links** … … 21 23 ## Installation ## 22 24 23 * Install the plugin from the 'Plugins' section in your dashboard (Go to `Plugins > Add New > Search` and search for 'WooCom erce Colored Order Notes').25 * Install the plugin from the 'Plugins' section in your dashboard (Go to `Plugins > Add New > Search` and search for 'WooCommerce Colored Order Notes'). 24 26 * Alternatively, you can [download](http://downloads.wordpress.org/plugin/colored-order-notes-for-woocommerce.zip "Download WooCommerce Colored Order Notes") the plugin from the repository. Unzip it and upload it to the plugins folder of your WordPress installation (`wp-content/plugins/` directory of your WordPress installation). 25 27 * Activate it through the 'Plugins' section. … … 53 55 ## Changelog ## 54 56 55 ### 1.0 ### 56 * First Public Release - 30th Jan 2016 57 ### 1.0.1 - 2017-05-03 ### 58 * Updated the code to work with WordPress 4.7.4 and WooCommerce 3.0.5 59 60 ### 1.0 - 2016-01-30 ### 61 * First Public Release -
colored-order-notes-for-woocommerce/trunk/readme.txt
r1489623 r1657910 1 1 === WooComerce Colored Order Notes === 2 Contributors: prasad-nevase 2 Contributors: prasad-nevase, chandrapatel 3 3 Tags: woocommerce custom order note color, order note color, colored order note, coloured order notes, woocommerce coloured order notes 4 4 Requires at least: WordPress 4.4 or above 5 Tested up to: 4. 66 Stable tag: 1.0 5 Tested up to: 4.7.0 6 Stable tag: 1.0.1 7 7 License: GPLv3 8 8 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 14 14 WooCommerce Colored Order Notes plugin allows you to to customize order note color for each order status. The plugin is made to work with WooCommerce version 2.5 or higher. Upon activating the plugin you will see "Order Note Colors" tab under "WooCommerce > Settings". 15 15 16 **Note** 17 This plugin works only with English (en_US) locale currently. 16 18 17 19 **Important Links** … … 51 53 == Changelog == 52 54 53 = 1.0 = 55 = 1.0.1 - 2017-05-03 = 56 * Updated the code to work with WordPress 4.7.4 and WooCommerce 3.0.5 57 58 = 1.0 - 2016-01-30 = 54 59 * First Public Release - 30th Jan 2016 -
colored-order-notes-for-woocommerce/trunk/woocommerce-colored-order-notes.php
r1339551 r1657910 1 1 <?php 2 2 /** 3 * WooCommerce Colored Order Notes 4 * 5 * @package WooCommerceColoredOrderNotes 6 * @author Prasad Nevase 7 * @copyright 2016 Your Name or Company Name 8 * @license GPLv3 9 * 3 10 * Plugin Name: WooCommerce Colored Order Notes 4 11 * Plugin URI: https://wordpress.org/plugins/woocommerce-colored-order-notes/ 5 12 * Description: Assign custom colors to WooCommerce order notes from backend. 6 * Version: 1.0 13 * Version: 1.0.1 7 14 * Author: Prasad Nevase 8 15 * Author URI: https://about.me/prasad.nevase … … 11 18 */ 12 19 13 if ( !defined( 'ABSPATH' ) ) { 14 exit; 15 } // Exit if accessed directly 16 17 if ( !class_exists( 'WC_Settings_Order_Note_Colors' ) ) { 18 19 class WC_Settings_Order_Note_Colors { 20 21 function __construct() { 22 23 add_action( 'init', array( $this, 'init' ) ); 24 25 } 26 27 /** 28 * Bootstraps the class and hooks required actions & filters. 29 * 30 */ 31 public static function init() { 32 33 if( version_compare( WC()->version, '2.5.0', '<' ) ) { 34 35 return add_action( 'admin_notices', __CLASS__ . '::wc_onc_admin_notices' ); 36 37 } 38 39 add_filter( 'woocommerce_settings_tabs_array', __CLASS__ . '::wc_onc_add_settings_tab', 50 ); 40 add_filter('woocommerce_order_note_class', __CLASS__ . '::wc_onc_process_note_classes', 10, 2); 41 add_action( 'woocommerce_settings_tabs_order_note_color', __CLASS__ . '::wc_onc_settings_tab' ); 42 add_action( 'woocommerce_update_options_order_note_color', __CLASS__ . '::wc_onc_update_settings' ); 43 add_action( 'admin_head', __CLASS__ . '::wc_onc_css' ); 44 } 45 46 47 /** 48 * Shows admin notice if WooCommerce version is below 2.5 49 * 50 */ 51 public static function wc_onc_admin_notices() { 52 echo '<div class="error"><p>' . __( '<strong>WooCommerce Order Note Colors</strong> plugin requires WooCommerce version 2.5.0 or higher. Please take necessary backup, update WooCommerce then deactivate & activate this plugin.', 'colored-order-notes-for-woocommerce' ) . '</p></div>'; 53 } 54 55 /** 56 * Add a new settings tab to the WooCommerce settings tabs array. 57 * 58 * @param array $settings_tabs Array of WooCommerce setting tabs & their labels, excluding the Subscription tab. 59 * @return array $settings_tabs Array of WooCommerce setting tabs & their labels, including the Subscription tab. 60 */ 61 public static function wc_onc_add_settings_tab( $settings_tabs ) { 62 $settings_tabs['order_note_color'] = __( 'Order Note Colors', 'colored-order-notes-for-woocommerce' ); 63 return $settings_tabs; 64 } 65 66 67 /** 68 * Uses the WooCommerce admin fields API to output settings via the @see woocommerce_admin_fields() function. 69 * 70 * @uses woocommerce_admin_fields() 71 * @uses self::get_settings() 72 */ 73 public static function wc_onc_settings_tab() { 74 woocommerce_admin_fields( self::wc_onc_get_settings() ); 75 } 76 77 /** 78 * Uses the WooCommerce options API to save settings via the @see woocommerce_update_options() function. 79 * 80 * @uses woocommerce_update_options() 81 * @uses self::get_settings() 82 */ 83 public static function wc_onc_update_settings() { 84 woocommerce_update_options( self::wc_onc_get_settings() ); 85 } 86 87 /** 88 * Get all the settings for this plugin for @see woocommerce_admin_fields() function. 89 * 90 * @return array Array of settings for @see woocommerce_admin_fields() function. 91 */ 92 public static function wc_onc_get_settings() { 93 94 $wc_onc_settings = array(); 95 $wc_onc_order_statuses = wc_get_order_statuses(); 96 97 $wc_onc_settings[] = array( 98 'name' => __( 'Order Note Colors', 'colored-order-notes-for-woocommerce' ), 99 'type' => 'title', 100 'desc' => 'Here you can specify the bacground color for order note based on order status', 101 'id' => 'wc_settings_order_note_colors' 102 ); 103 104 105 /* This loop will provide color setting option for all default + custom order status */ 106 107 foreach ( $wc_onc_order_statuses as $wc_onc_order_status ) { 108 109 $wc_onc_order_status_id = strtolower ( "onc_" . str_replace( ' ', '_', $wc_onc_order_status )); 110 111 $wc_onc_settings[] = array( 112 'name' => __( $wc_onc_order_status, 'colored-order-notes-for-woocommerce' ), 113 'type' => 'color', 114 'id' => $wc_onc_order_status_id 115 ); 116 117 } 118 119 $wc_onc_settings[] = array( 120 'type' => 'sectionend', 121 'id' => 'wc_settings_order_note_colors_end' 122 ); 123 124 125 return apply_filters( 'wc_settings_tab_order_note_color_settings', $wc_onc_settings ); 126 } 127 128 /** 129 * Append css class to $note_classes array based on the order status. 130 * 131 * @return array Array of note classes. 132 */ 133 134 public static function wc_onc_process_note_classes($note_classes, $note){ 135 136 $per_note_status = explode('to ', $note->comment_content ); 137 $onc_css_classes = self::wc_onc_get_settings(); 138 139 foreach ($onc_css_classes as $onc_css_class){ 140 141 if( $onc_css_class['type'] == 'color' && rtrim($per_note_status[1], "." ) == $onc_css_class['name'] ){ 142 143 $note_classes[] = $onc_css_class['id']; 144 } 145 146 } 147 148 return $note_classes; 149 } 150 151 /** 152 * Generate the css for each order status and place it in admin head 153 * 154 * @return css rules which are echoed inside admin <head></head> tag 155 */ 156 157 public static function wc_onc_css(){ 158 159 global $current_screen; 160 161 $onc_css = ""; 162 163 $onc_note_colors = self::wc_onc_get_settings(); 164 165 /* Check if the current page is for Order CPT (Either order listing or edit page) */ 166 167 if ( "shop_order" == $current_screen->post_type ) { 168 169 foreach ($onc_note_colors as $onc_note_color){ 170 171 if( $onc_note_color['type'] == 'color' ) { 172 173 $note_color = get_option($onc_note_color['id']); 174 175 if ( ! empty( $note_color ) ) { 176 177 $text_color = hexdec($note_color) > 0xffffff/2 ? 'black':'white'; 178 179 $onc_css .= ".note.". $onc_note_color['id'] . " .note_content { background: " . get_option($onc_note_color['id']) ."; color: ". $text_color . "; }"; 180 181 $onc_css .= " .note.". $onc_note_color['id'] . " .note_content:after { border-color: " . get_option($onc_note_color['id']) ." transparent;}"; 182 } 183 } 184 } 185 186 /* Finaly print the css */ 187 188 echo "<style>". $onc_css . "</style>"; 189 190 } 191 } 192 } 20 if ( ! defined( 'ABSPATH' ) ) { 21 exit; 193 22 } 194 23 195 if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { 196 197 global $wc_onc; 198 199 $wc_onc = new WC_Settings_Order_Note_Colors; 24 if ( ! class_exists( 'WC_Settings_Order_Note_Colors' ) ) { 25 26 /** 27 * Class WC_Settings_Order_Note_Colors 28 */ 29 class WC_Settings_Order_Note_Colors { 30 31 /** 32 * Class Constructor 33 */ 34 function __construct() { 35 36 add_action( 'init', array( $this, 'init' ) ); 37 38 } 39 40 /** 41 * Bootstraps the class and hooks required actions & filters. 42 */ 43 public static function init() { 44 45 if ( version_compare( WC()->version, '2.5.0', '<' ) ) { 46 47 return add_action( 'admin_notices', __CLASS__ . '::wc_onc_admin_notices' ); 48 49 } 50 51 add_filter( 'woocommerce_settings_tabs_array', __CLASS__ . '::wc_onc_add_settings_tab', 50 ); 52 add_filter( 'woocommerce_order_note_class', __CLASS__ . '::wc_onc_process_note_classes', 10, 2 ); 53 add_action( 'woocommerce_settings_tabs_order_note_color', __CLASS__ . '::wc_onc_settings_tab' ); 54 add_action( 'woocommerce_update_options_order_note_color', __CLASS__ . '::wc_onc_update_settings' ); 55 add_action( 'admin_head', __CLASS__ . '::wc_onc_css' ); 56 57 } 58 59 60 /** 61 * Shows admin notice if WooCommerce version is below 2.5 62 */ 63 public static function wc_onc_admin_notices() { 64 echo '<div class="error"><p>' . esc_html__( '<strong>WooCommerce Order Note Colors</strong> plugin requires WooCommerce version 2.5.0 or higher. Please take necessary backup, update WooCommerce then deactivate & activate this plugin.', 'colored-order-notes-for-woocommerce' ) . '</p></div>'; 65 } 66 67 /** 68 * Add a new settings tab to the WooCommerce settings tabs array. 69 * 70 * @param array $settings_tabs Array of WooCommerce setting tabs & their labels, excluding the Subscription tab. 71 * @return array $settings_tabs Array of WooCommerce setting tabs & their labels, including the Subscription tab. 72 */ 73 public static function wc_onc_add_settings_tab( $settings_tabs ) { 74 $settings_tabs['order_note_color'] = __( 'Order Note Colors', 'colored-order-notes-for-woocommerce' ); 75 return $settings_tabs; 76 } 77 78 79 /** 80 * Uses the WooCommerce admin fields API to output settings via the @see woocommerce_admin_fields() function. 81 * 82 * @uses woocommerce_admin_fields() 83 * @uses self::get_settings() 84 */ 85 public static function wc_onc_settings_tab() { 86 woocommerce_admin_fields( self::wc_onc_get_settings() ); 87 } 88 89 /** 90 * Uses the WooCommerce options API to save settings via the @see woocommerce_update_options() function. 91 * 92 * @uses woocommerce_update_options() 93 * @uses self::get_settings() 94 */ 95 public static function wc_onc_update_settings() { 96 woocommerce_update_options( self::wc_onc_get_settings() ); 97 } 98 99 /** 100 * Get all the settings for this plugin for @see woocommerce_admin_fields() function. 101 * 102 * @return array Array of settings for @see woocommerce_admin_fields() function. 103 */ 104 public static function wc_onc_get_settings() { 105 106 $wc_onc_settings = array(); 107 $wc_onc_order_statuses = wc_get_order_statuses(); 108 109 $wc_onc_settings[] = array( 110 'name' => __( 'Order Note Colors', 'colored-order-notes-for-woocommerce' ), 111 'type' => 'title', 112 'desc' => 'Here you can specify the bacground color for order note based on order status', 113 'id' => 'wc_settings_order_note_colors', 114 ); 115 116 /* This loop will provide color setting option for all default + custom order status */ 117 118 foreach ( $wc_onc_order_statuses as $wc_onc_order_status ) { 119 120 $wc_onc_order_status_id = strtolower( 'onc_' . str_replace( ' ', '_', $wc_onc_order_status ) ); 121 122 $wc_onc_settings[] = array( 123 'name' => $wc_onc_order_status, 124 'type' => 'color', 125 'id' => $wc_onc_order_status_id, 126 ); 127 128 } 129 130 $wc_onc_settings[] = array( 131 'type' => 'sectionend', 132 'id' => 'wc_settings_order_note_colors_end', 133 ); 134 135 return apply_filters( 'wc_settings_tab_order_note_color_settings', $wc_onc_settings ); 136 } 137 138 /** 139 * Append css class to $note_classes array based on the order status. 140 * 141 * @param Array $note_classes Array of note css classes. 142 * @param Object $note Object which holds all parameter for a note. 143 * @return Array $note_classes Array of note css classes. 144 */ 145 public static function wc_onc_process_note_classes( $note_classes, $note ) { 146 147 $per_note_status = explode( 'to ', $note->comment_content ); 148 $onc_css_classes = self::wc_onc_get_settings(); 149 150 foreach ( $onc_css_classes as $onc_css_class ) { 151 152 if ( 'color' === $onc_css_class['type'] && strtolower( rtrim( $per_note_status[ count( $per_note_status ) - 1 ], '.' ) ) === strtolower( $onc_css_class['name'] ) ) { 153 154 $note_classes[] = $onc_css_class['id']; 155 } 156 } 157 158 return $note_classes; 159 } 160 161 /** 162 * Generate the css for each order status and place it in admin head 163 */ 164 public static function wc_onc_css() { 165 166 global $current_screen; 167 168 $onc_css = ''; 169 170 $onc_note_colors = self::wc_onc_get_settings(); 171 172 /* Check if the current page is for Order CPT (Either order listing or edit page) */ 173 174 if ( 'shop_order' === $current_screen->post_type ) { 175 176 foreach ( $onc_note_colors as $onc_note_color ) { 177 178 if ( 'color' === $onc_note_color['type'] ) { 179 180 $note_color = get_option( $onc_note_color['id'] ); 181 182 if ( ! empty( $note_color ) ) { 183 184 $text_color = hexdec( $note_color ) > 0xffffff / 2 ? 'black' : 'white'; 185 186 $onc_css .= '.note.' . $onc_note_color['id'] . ' .note_content { background: ' . get_option( $onc_note_color['id'] ) . ' !important; color: ' . $text_color . '; }'; 187 188 $onc_css .= ' .note.' . $onc_note_color['id'] . ' .note_content:after { border-color: ' . get_option( $onc_note_color['id'] ) . ' transparent !important; }'; 189 } 190 } 191 } 192 193 /* Finaly print the css */ 194 echo '<style>' . wp_kses_post( $onc_css ) . '</style>'; 195 196 } 197 } 198 } 199 } // End if(). 200 201 if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) ) { 202 203 global $wc_onc; 204 205 $wc_onc = new WC_Settings_Order_Note_Colors; 200 206 201 207 }
Note: See TracChangeset
for help on using the changeset viewer.