/** * Output custom column content * * @since 1.0.0 * @param string $column * @param int $post_id */ public function custom_column_content($column, $post_id) { $status = new WC_Order_Status_Manager_Order_Status($post_id); switch ($column) { case 'icon': $color = $status->get_color(); $icon = $status->get_icon(); $style = ''; if ($color) { if ($icon) { $style = 'color: ' . $color . ';'; } else { $style = 'background-color: ' . $color . '; color: ' . wc_order_status_manager()->icons->get_contrast_text_color($color) . ';'; } } if (is_numeric($icon)) { $icon_src = wp_get_attachment_image_src($icon, 'wc_order_status_icon'); if ($icon_src) { $style .= 'background-image: url( ' . $icon_src[0] . ');'; } } printf('<mark class="%s %s tips" style="%s" data-tip="%s">%s</mark>', sanitize_title($status->get_slug()), $icon ? 'has-icon ' . $icon : '', $style, esc_attr($status->get_name()), esc_html($status->get_name())); break; case 'slug': echo esc_html($status->get_slug()); break; case 'description': echo esc_html($status->get_description()); break; case 'type': printf('<span class="badge %s">%s</span>', sanitize_title($status->get_type()), esc_html($status->get_type())); break; } }
/** * Print styles for custom order status icons * * @since 1.0.0 */ public function custom_order_status_icons() { $custom_status_colors = array(); $custom_status_badges = array(); $custom_status_icons = array(); $custom_action_icons = array(); foreach (wc_get_order_statuses() as $slug => $name) { $status = new WC_Order_Status_Manager_Order_Status($slug); // Sanity check: bail if no status was found. // This can happen if some statuses are registered late if (!$status || !$status->get_id()) { continue; } $color = $status->get_color(); $icon = $status->get_icon(); $action_icon = $status->get_action_icon(); if ($color) { $custom_status_colors[esc_attr($status->get_slug())] = $color; } // Font icon if ($icon && ($icon_details = wc_order_status_manager()->icons->get_icon_details($icon))) { $custom_status_icons[esc_attr($status->get_slug())] = $icon_details; } elseif (is_numeric($icon) && ($icon_src = wp_get_attachment_image_src($icon, 'wc_order_status_icon'))) { $custom_status_icons[esc_attr($status->get_slug())] = $icon_src[0]; } elseif (!$icon) { $custom_status_badges[] = esc_attr($status->get_slug()); } // Font action icon if ($action_icon && ($action_icon_details = wc_order_status_manager()->icons->get_icon_details($action_icon))) { $custom_action_icons[esc_attr($status->get_slug())] = $action_icon_details; } elseif (is_numeric($action_icon) && ($action_icon_src = wp_get_attachment_image_src($action_icon, 'wc_order_status_icon'))) { $custom_action_icons[esc_attr($status->get_slug())] = $action_icon_src[0]; } } ?> <!-- Custom Order Status Icon styles --> <style type="text/css"> /*<![CDATA[*/ <?php // General styles for status badges ?> <?php if (!empty($custom_status_badges)) { ?> .widefat .column-order_status mark.<?php echo implode(', .widefat .column-order_status mark.', $custom_status_badges); ?> { display: inline-block; font-size: 0.8em; line-height: 1.1; text-indent: 0; background-color: #666; width: auto; height: auto; padding: 0.4em; color: #fff; border-radius: 2px; word-wrap: break-word; max-width: 100%; } .widefat .column-order_status mark.<?php echo implode(':after, .widefat .column-order_status mark.', $custom_status_badges); ?> :after { display: none; } <?php } ?> <?php // General styles for status icons ?> <?php if (!empty($custom_status_icons)) { ?> <?php $custom_status_font_icons = array_filter($custom_status_icons, 'is_array'); ?> <?php if (!empty($custom_status_font_icons)) { ?> .widefat .column-order_status mark.<?php echo implode(':after, .widefat .column-order_status mark.', array_keys($custom_status_font_icons)); ?> :after { speak: none; font-weight: normal; font-variant: normal; text-transform: none; line-height: 1; -webkit-font-smoothing: antialiased; margin: 0; text-indent: 0; position: absolute; top: 0; left: 0; width: 100%; height: 100%; text-align: center; } <?php } ?> <?php } ?> <?php // General styles for action icons ?> .widefat .column-order_actions a.button { padding: 0 0.5em; height: 2em; line-height: 1.9em; } <?php if (!empty($custom_action_icons)) { ?> <?php $custom_action_font_icons = array_filter($custom_action_icons, 'is_array'); ?> <?php if (!empty($custom_action_font_icons)) { ?> .order_actions .<?php echo implode(', .order_actions .', array_keys($custom_action_icons)); ?> { display: block; text-indent: -9999px; position: relative; padding: 0!important; height: 2em!important; width: 2em; } .order_actions .<?php echo implode(':after, .order_actions .', array_keys($custom_action_icons)); ?> :after { speak: none; font-weight: 400; font-variant: normal; text-transform: none; -webkit-font-smoothing: antialiased; margin: 0; text-indent: 0; position: absolute; top: 0; left: 0; width: 100%; height: 100%; text-align: center; line-height: 1.85; } <?php } ?> <?php } ?> <?php // Specific status icon styles ?> <?php if (!empty($custom_status_icons)) { ?> <?php foreach ($custom_status_icons as $status => $value) { ?> <?php if (is_array($value)) { ?> .widefat .column-order_status mark.<?php echo $status; ?> :after { font-family: "<?php echo $value['font']; ?> "; content: "<?php echo $value['glyph']; ?> "; } <?php } else { ?> .widefat .column-order_status mark.<?php echo $status; ?> { background-size: 100% 100%; background-image: url( <?php echo $value; ?> ); } <?php } ?> <?php } ?> <?php } ?> <?php // Specific status color styles ?> <?php if (!empty($custom_status_colors)) { ?> <?php foreach ($custom_status_colors as $status => $color) { ?> <?php if (in_array($status, $custom_status_badges)) { ?> .widefat .column-order_status mark.<?php echo $status; ?> { background-color: <?php echo $color; ?> ; color: <?php echo wc_order_status_manager()->icons->get_contrast_text_color($color); ?> ; } <?php } ?> <?php if (isset($custom_status_icons[$status])) { ?> .widefat .column-order_status mark.<?php echo $status; ?> :after { color: <?php echo $color; ?> ; } <?php } ?> <?php } ?> <?php } ?> <?php // Specific action icon styles ?> <?php if (!empty($custom_action_icons)) { ?> <?php foreach ($custom_action_icons as $status => $value) { ?> <?php if (is_array($value)) { ?> .order_actions .<?php echo $status; ?> :after { font-family: "<?php echo $value['font']; ?> "; content: "<?php echo $value['glyph']; ?> "; } <?php } else { ?> .order_actions .<?php echo $status; ?> , .order_actions .<?php echo $status; ?> :focus, .order_actions .<?php echo $status; ?> :hover { background-size: 69% 69%; background-position: center center; background-repeat: no-repeat; background-image: url( <?php echo $value; ?> ); } <?php } ?> <?php } ?> <?php } ?> /*]]>*/ </style> <?php }