get_settings()); } public function update_settings() { woocommerce_update_options($this->get_settings()); } public function get_settings(){ $settings = []; $statuses = wc_get_order_statuses(); $settings[] = [ 'name' => __('Order Note Colors', 'admin-order-notes-status-highlighter'), 'type' => 'title', 'desc' => __('Assign background colors to order notes based on order status.', 'admin-order-notes-status-highlighter'), 'id' => 'aonsh_settings_note_colors' ]; foreach ($statuses as $status_key => $label) { $settings[] = [ 'name' => $label, 'type' => 'color', 'id' => 'aonsh_note_' . sanitize_title($label) ]; } $settings[] = ['type' => 'sectionend', 'id' => 'aonsh_settings_note_colors_end']; $settings[] = [ 'name' => __('Order Status Badge Colors', 'admin-order-notes-status-highlighter'), 'type' => 'title', 'desc' => __('Customize admin order status badge colors.', 'admin-order-notes-status-highlighter'), 'id' => 'aonsh_settings_badge_colors' ]; foreach ($statuses as $status_key => $label) { $slug = str_replace('wc-', '', $status_key); $settings[] = [ 'name' => $label, 'type' => 'color', 'id' => 'aonsh_badge_' . $slug ]; } $settings[] = ['type' => 'sectionend', 'id' => 'aonsh_settings_badge_colors_end']; return $settings; } public function color_classes($classes,$note){ $content = !empty($note->content) ? $note->content : (!empty($note->comment_content) ? $note->comment_content : ''); if(!$content) return $classes; $statuses=wc_get_order_statuses(); foreach($statuses as $key=>$label){ if(stripos($content,$label)!==false){ $classes[]='aonsh_note_'.sanitize_title($label); } } return $classes; } public function css(){ global $current_screen; if(empty($current_screen) || $current_screen->post_type!=='shop_order') return; $css=''; $statuses=wc_get_order_statuses(); foreach($statuses as $key=>$label){ $id='aonsh_note_'.sanitize_title($label); $color=get_option($id); if($color){ $hex=ltrim($color,'#'); $text=(hexdec($hex)>0xffffff/2)?'black':'white'; $css.=".note.$id .note_content{background:$color!important;color:$text!important;}"; $css.=".note.$id .note_content:after{border-color:$color transparent!important;}"; } } foreach($statuses as $key=>$label){ $slug=str_replace('wc-','',$key); $id='aonsh_badge_'.$slug; $color=get_option($id); if($color){ $hex=ltrim($color,'#'); $text=(hexdec($hex)>0xffffff/2)?'black':'white'; $css.="mark.order-status.status-$slug{background:$color!important;color:$text!important;}"; } } echo ""; } } } // Instantiate the class after plugins load add_action('plugins_loaded', function () { new AONSH_Settings(); });