Have you ever try to add an extra new custom field to your WordPress blog post and trying to find a solution until the cows come home? Well, let me show you the rope on how to add a new custom field to your WordPress blog post easily using WooCommerce product home page as an example. Here, you can see that an extra new custom field NEW has been added to the product item besides having the title and the pricing by default.

Adding a New Custom Field to Your WordPress Blog Post

First and foremost, you will need to insert a new custom field when creating your product item. Locate Add New Custom Field: and click on Enter new to continue. Enter tag under the Name field and NEW under the Value fieldClick on Add Custom Field when done. This will create a permanent custom field tag with a value New for this specific product item.

Adding a New Custom Field to Your WordPress Blog Post

Now, you’ll need to make some adjustment on the WooCommerce product home page so that the custom field NEW can show up. Click on the following link: WordPress Plugin (WooCommerce) – Insert Short Description on Home Page to learn how to locate the required file: content-product.php and enter the following lines to insert the custom field. The coding basically tells WordPress to display the value if the custom field tag value is not blank.

 

<?php if(get_post_meta(get_the_ID() , “tag”, true) != “”) { ?> <span style=”background-color:#FF0000;color:#FFFFFF;padding:3px”><?php echo get_post_meta(get_the_ID() , “tag”, true); ?></span> <?php } ?>
%d bloggers like this: