If description tab empty show custom field
-
Support,
I’ve looked extensively and cannot work this out.
If there is nothing in the description field, I want to show a custom field.
We’ve linked WooCommerce with LightSpeed and it’s a bit of a mess how the data has been pulled in, but that’s for another day.
At the moment, if the description field is empty, it hides the tab which is great for most cases.
However, on my instance I want to say that if the Description is empty then load my custom field.
I have created a function to show the custom field (which works fine, pulls in what I need if not in the if statement)
function showSomething() { global $post; $post_id = $post->ID; $postMeta = get_post_meta($post_id, '_wclsi_ls_obj', true); $CustomFieldValues = $postMeta->CustomFieldValues->CustomFieldValue->value; print_r ($CustomFieldValues); }
Then I thought I would simply do a basic if statement as the below but doesn’t work with the function.
<?php if(empty($tabs['description'])) { ?> <?php showSomething(); ?><?php } ?>
If I change the condition to true, it works (but obviously in the wrong section.
<?php if(!empty($tabs['description'])) { ?> <footer> <?php showSomething(); ?><?php echo 'something'?> </footer> <?php } ?>
If I replace the function showSomething in the if statement for a simple echo request, the logic works.
<?php if(empty($tabs['description'])) { ?> <footer> <?php echo 'hello'; ?></footer> <?php } ?>
Any thoughts please?
Many thanks,
- The topic ‘If description tab empty show custom field’ is closed to new replies.