Search code examples
phpwordpresswoocommercehook-woocommerce

Hide the label in an output form when an input field is empty


For a custom form field I don't want to display the field label if an input field is empty. Also, how can I reduce the space between two result outputs?

I added the Populated get check custom tab. I created and saved custom fields data fields to call data by:

$source = get_post_meta($post->ID, '_inputtext', true);

$result = '<div class="custom-data">';
if(! empty($output))
    $result .= '<p>' . __('<span style="color:#96588a; " text-align: left;">Sell In:</span> ') . '<span style="color:#96588a;">' . $source . '</span></p>';

But this displays the label even when true and the second does not display as the required field.


Solution

  • As my understadnig ,you need to check $source varibale. Isn't it ?

    if(!empty($source)){
      // then do the rest 
     }