Author Topic: Do not display product description if empty  (Read 1209 times)

Picklehead

  • Beginner
  • *
  • Posts: 11
  • A beginner
Do not display product description if empty
« on: January 10, 2022, 01:43:15 am »
Hi All,

Is there a way to hide the product description on product details page but only if the field is empty?

Any help would be great.

Phil.

AH

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3510
  • VirtueMart Version: 3.8.9
Re: Do not display product description if empty
« Reply #1 on: January 10, 2022, 11:24:10 am »
That is the default VM product view behaviour

Code: [Select]
if (!empty($this->product->product_desc)) {
Regards
A

Joomla 3.9.27
php 7.4

Picklehead

  • Beginner
  • *
  • Posts: 11
  • A beginner
Re: Do not display product description if empty
« Reply #2 on: January 10, 2022, 13:57:15 pm »
Thank you for the reply,

I do have the !empty code in my template but i am still seeing the description.

This is the code

    <?php  if (!empty($this->product->product_desc)) { ?>
        <h2> <?php echo JText::_('COM_VIRTUEMART_PRODUCT_DESC_TITLE'); ?></h2>
        <div>
           <?php echo '<div class="desc">' .$this->product->product_desc.'</div>'; ?>
         <?php
   if (!empty($this->product->customfieldsSorted['tags'])) {
   $this->position = 'tags';
   echo '<div class="tags">' .$this->loadTemplate('tags').'</div>';
   }
   ?>
        </div>
   <?php } ?>

But the description still shows even after clearing cache.


Jörgen

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3921
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: Do not display product description if empty
« Reply #3 on: January 10, 2022, 14:27:34 pm »
Change
Code: [Select]
<h2> <?php echo JText::_('COM_VIRTUEMART_PRODUCT_DESC_TITLE'); ?></h2>to
Code: [Select]
<h2> <?php echo 'Descr title : ' .  JText::_('COM_VIRTUEMART_PRODUCT_DESC_TITLE'); ?></h2>
In order to see if this is the code that is used :)

Jörgen
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

Picklehead

  • Beginner
  • *
  • Posts: 11
  • A beginner
Re: Do not display product description if empty
« Reply #4 on: January 10, 2022, 15:20:26 pm »
Thank you for the reply.

I have tested the code and the code extract posted is definitely being used.

Will investigate further and see if I can find the cause of the problem.

Kind Regards,
Phil

 

Jörgen

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3921
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: Do not display product description if empty
« Reply #5 on: January 10, 2022, 16:01:54 pm »
Are there maybe some invisible characters in the description ?

Jörgen
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

Picklehead

  • Beginner
  • *
  • Posts: 11
  • A beginner
Re: Do not display product description if empty
« Reply #6 on: January 10, 2022, 16:13:40 pm »
Thanks again!

Checked again and no hidden characters in the description, so I am currently checking for conflicts with modules and plugins

Jörgen

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3921
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: Do not display product description if empty
« Reply #7 on: January 10, 2022, 16:55:42 pm »
Have You checked with str_len(description)?

Jörgen
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

Picklehead

  • Beginner
  • *
  • Posts: 11
  • A beginner
Re: Do not display product description if empty
« Reply #8 on: January 12, 2022, 00:08:18 am »
Hi Jörgen,
Thank you for the suggestion which I checked and everything  correct.

I have today been checking into this and found that if I have an editor enabled in Joomla then the product description displays despite being empty, but if set the Joomla Editor to 'None' then the description does not show. However this does not happen on any of my other themes so there must be something I am missing.

Kind Regards
Phil

Jörgen

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3921
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: Do not display product description if empty
« Reply #9 on: January 12, 2022, 08:13:55 am »
Are you really sure that the description is empty ?

To me it looks like the editor puts in something like this:
Code: [Select]
<p>&nbsp;</p>
Check Your settings for the editor :)

Jörgen
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

Picklehead

  • Beginner
  • *
  • Posts: 11
  • A beginner
Re: Do not display product description if empty
« Reply #10 on: January 18, 2022, 13:41:32 pm »
Hi,
Just a quick post to say that we found the issue.

We use SP Pagebuilder within on some of our product descriptions and we have modified our code to ensure the description fields always remain empty if using this plugin.

Thanks to all for the help!!

Phil

Jörgen

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3921
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: Do not display product description if empty
« Reply #11 on: January 18, 2022, 15:15:36 pm »
Glad to be of help. Looking for empty data in php works, usually the string is not empty after all...

Jörgen
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.