1

My code displays an image if the order status change matches the image name. However I have some order status' with no image and in this case there is an error where the picture cannot be found on the server.

I want to display an If Else statement where the image only shows if it matches the status name else if displays nothing.

<img src="<?php print get_template_directory_uri().'/images/truck-'.$order->status; ?>.png" />

2 Answers 2

1

You can use the php function file_exists(). Here an example snippet:

<?php
if(file_exists(get_template_directory_uri().'/images/truck-'.$order->status.'.png')) {
//display image
}
else {
//display a placeholder image
}
?>
Sign up to request clarification or add additional context in comments.

Comments

0

You can check if the file exists on the server with file_exists(string $filename) Or use a try catch statement

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.