You can do in the following way!
-
Create an array of CSS class names and message values
$colors_stings = array( 'Message one' => 'message_color_green', 'Message two' => 'message_color_red', 'Message three' => 'message_color_blue' );
-
Check if message string exist in array then assign CSS color class to variable.
$css_class = isset($colors_stings[$product_status]) ? $colors_stings[$product_status] : 'message_default_color';
Complete Example:-
$colors_stings = array(
'Message one' => 'message_color_green',
'Message two' => 'message_color_red',
'Message three' => 'message_color_blue'
);
$product_status = get_post_meta( $post->ID, 'productstatus_select', true );
$css_class = isset($colors_stings[$product_status]) ? $colors_stings[$product_status] : 'message_default_color';
echo '<p class="productstatus '. $css_class . '">' . $product_status .'</p>';
Related Posts:
- How to access custom order item meta data from a meta key in WooCommerce?
- Save Custom Fields for Variations Product
- Adding existing user custom field value to a woocommerce product [closed]
- Adding Custom Text Area to WooCommerce Product
- WooCommerce conditional required checkout fields [closed]
- Include woocommerce custom field value in front-end search result
- woocommerce product custom field
- How to get customfield value by woocommerce product ID
- Conditionally hide or show woocommerce product variation in fontend by custom field
- Woocommerce: Custom fields and email shortcodes, ec_custom_field
- Bulk remove post meta
- How to create html block to display extra information on woocommerce single product page
- Display WP-Types custom fields in post [closed]
- Modifying custom order item meta from admin order view
- How to create a dropdown select of all items in an ACF field group
- How do I add an image upload, custom field to a WooCommerce product?
- WooCommerce – Adding Custom Fields To Invoice
- Woocommerce Product Custom Select List (not variation)
- jQuery – Automatic event trigger does not **really** check my form
- How to add new field to the account address?
- How to display custom field in woocommerce email orders? [closed]
- Woocommerce Retrieving custom field value from orders
- Update custom field values on edit address page woocommerce
- Woocommerce frontend edit custom fields
- Is it possible to add Term Meta Fields to a WooCommerce Attribute?
- Why does my numeric meta query work only on one meta key and not the other?
- Update custom field on the fly
- (woocommerce) How to get product id form order id & then retrieve custom meta linked to product?
- How to delete WooCommerce Products than have a specific custom field?
- WooCommerce 3 get custom variation on process order [closed]
- How to save array option as text and not integer?
- Use a different catalog image than the featured image
- Check if value exists before saving
- Add Custom field under the post title [closed]
- woocommerce how in checkout to add my custom field check box, and when i check it hide the shipping adress and add tax 19% [closed]
- price calculation from custom field (woocommerce) [closed]
- Hiding custom fields when content is empty [closed]
- Cannot save values to custom fields for variations on Woocommerce 2.4.6
- Send checkout page custom field in order email
- Extract array from custom field
- How to add a custom field in the advanced menu properties?
- Underscores in custom fields
- Sortable Custom Columns in User Panel (users.php)?
- Adding Custom Field to Taxonomy Input :Panel
- Unable to get Preview of Uploaded image within a Custom Meta box
- How to filter or search the posts using postmeta tables custom meta fields with wordpress REST API
- Custom bulk action for media gallery items
- Localized Date Format for Custom Field
- Check if the value of a field has changed on save_post
- Saving custom image meta fields
- Echo values from custom field outside loop php
- Transfer self made functions.php custom fields to Advanced Custom Fields [closed]
- Complex WP_User_Query call fails on production server
- Query post order by post and desc not working
- If category then echo a custom fields
- How do I define post titles as images using Custom Fields?
- How to show Small Box Inside Content Area, which holds (text, images, links)?
- Sort custom field by post
- How to order posts by one custom field and filter them by another one?
- Can we create a WordPress read-only virtual field derived from three other fields?
- How to create a gallery custom field for WordPress post?
- How to display image inside container of custom made widget
- List users by sum of all their posts’ custom field values
- Duplicate (or more) custom fields on many posts. Is there an easy way to clean them up?
- Sort WP_Query with numeric custom field
- Enable a short code in the custom meta field
- Problem uploading different files as custom fields with front end post form
- How to change order of posts in admin
- Custom product fields in wp e-Commerce plugin [closed]
- How can I modify my meta_query to work with prices that are stored in the database that contain dollar signs and commas?
- How to add extra field in admin comment section
- wordpress multi user question
- How to sort post listing on a page using custom field value?
- Odd functions.php issue in WordPress
- Type character in name and make it invisble
- How to set up page fields with gutenberg instead of ACF
- Display custom field value in woocommerce variable product via jQurey
- Move the post title to another field
- ACF multi taxonomy on filterable gallery
- How to improve my non-unique metadata MySQL entries?
- Custom user registration fields in user_register hook
- Unable to change checkout placeholder text
- Store comment form custom field in custom database
- author.php not showing content if Author has no Posts
- How do I update custom field post meta in frontend post template?
- Sorting post by custom fileds date
- Custom Fields Not Working In Footer
- Add custom field to post with some part of url as value
- CSS conditional on custom field value
- My meta boxes update wp_postmeta of posts but not of pages. What is wrong with the code?
- WP Post Meta Box Field Not Showing Updated Field
- WP_Query based on multiple metadata comparisons
- same custom field for single posts
- Import data from arbitrary CSV to WPAlchemy meta fields
- Alter SQL query to return posts with unique custom field value, no duplicate values
- custom field output after the_content
- Insert shortcode before and after a list automatically
- Post count by meta_key meta_value [closed]
- Change post status by custom fields
- update_post_meta based on acf repeater field