I try to change the color of an order-status-span-element to color red, if the order status is "Pending payment".
As soon as the status changes to "completed", the span text color should switch to green.
Here is the clean div code:
<div class="order-status">
<span>Order Status</span>
<?php elseif ( 'order-status' === $column_id ) : ?>
<?php echo '<span id="order-status-value">' . esc_html( wc_get_order_status_name( $order->get_status() ) ) . '<span>'; ?>
</div>
I tried to insert a proper if-statement, but I don’t know which function or variable I need to insert.
This is the snippet is only a part of my orders.php ->(…/my-account/orders).
<div class="order-status">
<span>Order Status</span>
<?php elseif ( 'order-status' === $column_id ) : ?>
<?php echo '<span id="order-status-value">' . esc_html( wc_get_order_status_name( $order->get_status() ) ) . '<span>';
if ( strcasecmp( wc_get_order_status_name( $order->get_status() ) == 0 ) ) :
echo "The if statement works!";
?>
<style type="text/css">
#order-status-value {
color: green;
}
</style>
<?php
else:
?>
<style type="text/css">
#order-status-value {
color: red;
}
</style>
</div>
</div>
This code doesn’t work.
2
Answers
Here is the solution I use at the moment - this one works perfectly.
You could use the "style" HTML attribute to change the color :