Is there a way to customize the appearance of the "Backordered: " text within the Order Edit section of WP-admin?

I am looking to customize the appearance of the TR element where Woocommerce displays the "Backordered" text in wp-admin on the Order edit page. I would like this styling to apply to both the order edit page and the "order quick view" modal.

The challenge I am facing is that there are no specific classes or IDs to target with my CSS.

    <table cellspacing="0" class="display_meta">
     <tbody>
//  THE FOLLOWING TR NEEDS STYLING
       <tr> 
        <th>Backordered:</th>
          <td><p>2</p></td>
       </tr> 
// END OF FILE
       <tr>
        <th>Cost of goods:</th>
         <td><p>8,17</p></td>
       </tr>
       <tr>
        <th>Purchase price:</th>
         <td><p>8,17</p></td>
       </tr>
     </tbody>
    </table>

I attempted to use basic CSS like this:

table.display_meta tr:first-child {
    color: red !important;
}

While this did change the color as intended, it affected every first child TR, which is not desired when multiple meta fields are displayed per product on an order with many orderlines.

https://i.sstatic.net/e5XyC.png

I specifically want to highlight the backordered line to prevent premature packing by the warehouse personnel.

I believe adding some custom classes or utilizing a snippet may be the solution, although I have been unsuccessful in finding relevant examples through search engines.

If possible, styling the entire

<tr class="item">
surrounding the backordered item would also be acceptable if the correct class ID can be targeted.

Any suggestions or guidance would be greatly appreciated!

Answer №1

You have the ability to include an extra CSS class in the <tr> element of an item if the item has any meta data with a key of 'Backordered', by utilizing the

woocommerce_admin_html_order_item_class
filter.

If you also want to apply this to the order preview modal, you can make use of the

woocommerce_admin_html_order_preview_item_class
filter.

add_filter( 'woocommerce_admin_html_order_item_class', 'woocommerce_admin_html_order_item_add_backorder_class', 10, 3 );
add_filter( 'woocommerce_admin_html_order_preview_item_class', 'woocommerce_admin_html_order_item_add_backorder_class', 10, 3 );
function woocommerce_admin_html_order_item_add_backorder_class( $class, $item, $order ) {
    foreach ( $item->get_formatted_meta_data( '_', true ) as $meta_id => $meta_data ) {
        if ( strpos( $meta_data->key, 'Backordered' ) !== false ) {
            $class .= 'backordered-item';
            break;
        }
    }
    return $class;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ensure that the content inside the page has an overflow auto setting

When looking at the image, it is clear that I do not want my page to be scrollable. Researching the issue, I discovered that setting the height to 100vh is the solution (How to make a div 100% height of the browser window). I then set elements like 4 and 5 ...

Is there a way to get Axios to display CSS on the page?

While working on a Web Viewer project with axios for web scraping practice, I encountered an issue where the CSS wasn't loading properly. Here is the code snippet I used: console.log("Tribble-Webviewer is starting!") const express = requir ...

Tips on Incorporating CSS in import.io Connect Extract

By utilizing the import.io connector, I successfully extracted a portion of HTML from the source website. The output was returned as "html" type, consisting of a single table of data with styles defined in the body HTML but not fully extracted. Consequentl ...

Instructions on filling the star icon with color upon clicking the button

Currently working on a project using codeIgniter where I have a form for rating products. I am facing an issue where, upon clicking the star button, only the border color changes to yellow while the center of the button remains white. Can someone please g ...

Customize the border of the Tab indicator within Material UI

I created a custom NavBar with a unique tab indicator implementation: indicator: { background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)', }, <Tabs classes={{indicator: classes.indicator}} onChange={handleClickTab} value={value}> ...

Is there a way to create an X shape by rotating two divs when I click on the container div?

I currently have this setup: code Below is the HTML code: <div id="box"> <div id="line1" class="line"></div> <div id="line2" class="line"></div> <div id="line3" class="line"></div> </div> My go ...

How can you utilize CSS to automatically generate section numbers, specifically for multiple sections?

Is it possible to automatically generate section numbering in CSS only when there are multiple sections present? I discovered that using CSS, one can create automatic numbering for sections. body { counter-reset: section } h2 { counter-reset: sub-section ...

What is causing the breakdown of bordered tables in Bootstrap when the border-separate property is set to collapse?

I am experiencing an issue with my bordered table that is using the Bootstrap classes table table-bordered. When I add border-collapse: separate, the borders are correctly separated, but the top and bottom borders seem to disappear due to zero width. I am ...

What are the different ways to utilize the "%" symbol in CSS for adjusting the size of elements?

I have attempted multiple solutions, however, the percentage symbol is the only thing that is not working. I am unsure of the reason for this issue. p{ width:100%; } ...

`Flexbox: Achieving Alignment of Items``

I am looking to align items in a specific way. My goal is to have 4 items in one row, and then the remaining 3 items in the next row, all centered. Despite setting the width at 25%, I am encountering some issues with alignment. Please check out the code ...

Tips for adjusting the size of Angular Material elements

In the midst of my work on an Angular application, I have been utilizing angular material components. However, as I delved into styling the application, I encountered difficulties in styling the angular material component, particularly in enlarging a dropd ...

What is the best approach to create a JavaScript search filter function spanning two pages?

Page1.html has a form with a drop-down menu containing options Color and Shape. There is also a submit button. Assuming Page2.html displays various shapes like Blue Square, Red Square, Blue Circle, Red Circle, is it feasible to create a JavaScript file th ...

Not implementing auto-scroll feature because of the presence of `position: sticky` or `position: fixed` CSS properties

I'm encountering a console warning while working on my Nextjs project. Here is the snippet of my code: <aside className={`site-off desktop-hide ${showMenu ? "show-menu" : ""}`}> .... </aside> And here is the relevant ...

Is it possible to assign a width property to a div element?

I want DivTest and IdOtherDIV to have the same width. I attempted to set properties like this: DivTest { background: #007C52; width: document.getElementById("IdOtherDIV").scrollWidth + "px.\n"; } Is there a way to achieve this (considering tha ...

When an absolute positioned element exceeds the right border of its relative parent, its width will be truncated

When position: absolute; divs are placed inside or around a position: relative; parent, their height and width are based on the size and length of the text they contain. However, if one of these divs extends beyond the right border of the relative parent, ...

Is there a way to display a different file, such as index.html, based on the screen width?

I'm facing an issue. I have completed a web page (with HTML, CSS, and JavaScript), but now I want to create a mobile version using different HTML files, another index.html file, and a separate CSS file. What changes do I need to make in the main page ...

Analyzing the browser's address bar and creating a navigation link derived from it

Is there a way to create a script that can extract information from the address bar? For example, if we have a link like this: We want to be able to take the "page-2011" part and dynamically generate navigation links like this: « <a href="/page-2010 ...

Setting a div's width to cover 100% of the screen's width

I'm currently working on creating a 2 column layout using divs. The left column has a fixed size of 150 px, while the right column should extend to the right boundary of the browser. I've tried using both width:auto and width:100% values for the ...

Is there a way to incorporate a delete button for each li element that is included in my list?

I have successfully implemented a to-do list where clicking on an item strikes a line through it and there is a delete button that works. However, I am looking for assistance on how to create a delete button for each newly added li item. var button = do ...

Bug with IOS double tap on Element UI VueJS select input element

Encountering a strange problem on iOS safari or chrome. When attempting to select an option from a dropdown input, the options show up correctly on the first tap, but when trying to actually select an option, it requires two taps to work properly. This is ...