You are here:  » Extra fields


Extra fields

Submitted by henk on Sat, 2012-12-15 21:51 in

Hi David,

I have some extra fields after product description, is it possible when it's empty not to show them:

{link saved}

the following extra fields are empty, is this with endif?....

Verzendkosten:

Voorraad:

Cheers,
Henk

Submitted by support on Sun, 2012-12-16 11:56

Hello Henk,

You could make the text %IFDB_fieldname% conditional quite easily. In pto_product.php look for the following code at line 130:

  $each = str_replace("%DB_".$field."%",$product->$field,$each);

...and REPLACE with:

  if ($product->$field)
  {
    $each = str_replace("%DB_".$field."%",$product->$field,$each);
    $each = str_replace("%IFDB_".$field."%","",$each);
    $each = str_replace("%ENDIFDB_".$field."%","",$each);
  }
  else
  {
    $each = preg_replace('/%IFDB_'.$field.'%(.*)%ENDIFDB_'.$field.'%/','',$each);
  }

Then in your template, use for example:

%IFDB_voorraad%Voorraad: %DB_voorraad%ENDIFDB_voorraad%

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Sun, 2012-12-16 15:44

Hi David,

There is an error on my page: No ending delimiter '/' found in line 145:

$each = preg_replace('/%IFDB_'.$field.'%(.*)%ENDIFDB_'.$field.'%','',$each);

Cheers Henk

Submitted by support on Sun, 2012-12-16 16:51

Sorry Henk, that line should be:

$each = preg_replace('/%IFDB_'.$field.'%(.*)%ENDIFDB_'.$field.'%/','',$each);

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Sun, 2012-12-16 17:04

No problem David,

But now the originals are:

Levertijd: %DB_levertijd%
Verzendkosten: %DB_verzendkosten%
Voorraad:

Thx
Henk

Submitted by support on Sun, 2012-12-16 17:22

Ooops - had the comparison the wrong way round...

  if ($product->$field)
  {
    $each = str_replace("%DB_".$field."%",$product->$field,$each);
    $each = str_replace("%IFDB_".$field."%","",$each);
    $each = str_replace("%ENDIFDB_".$field."%","",$each);
  }
  else
  {
    $each = preg_replace('/%IFDB_'.$field.'%(.*)%ENDIFDB_'.$field.'%/','',$each);
  }

(just remove ! from infront of $product->$field)

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Sun, 2012-12-16 21:55

Hi David,

Its not working,

%IFDB_voorraad%Voorraad: %DB_voorraad%%ENDIFDB_voorraad%

Still shown in product page.

And also the %DB_voorraad% is on suggested product.

Thx
Henk

Submitted by support on Mon, 2012-12-17 11:44

Hi Henk,

The location i'd copied the IF/ELSE construct code from used a different variable - this is the corrected replacement, which I've just checked out on my test server for you:

if ($product->$field)
{
  $html_product = str_replace("%DB_".$field."%",$product->$field,$html_product);
  $html_product = str_replace("%IFDB_".$field."%","",$html_product);
  $html_product = str_replace("%ENDIFDB_".$field."%","",$html_product);
}
else
{
  $html_product = preg_replace('/%IFDB_'.$field.'%(.*)%ENDIFDB_'.$field.'%/','',$html_product);
}

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Mon, 2012-12-17 20:02

Hi David,

And where can i change it in see next link:

{link saved}

Levertijd: %DB_levertijd%
Verzendkosten: %DB_verzendkosten%
Voorraad: %DB_voorraad%

Thx
Henk

Submitted by support on Tue, 2012-12-18 09:05

Hi Henk,

That's the price comparison table, this time within the pto_product_prices() function towards the top of pto_product.php look for the following code around line 130:

  $each = str_replace("%DB_".$field."%",$product->$field,$each);

....and REPLACE with (and this time it _is_ the variable $each!!)

if ($product->$field)
{
  $each = str_replace("%DB_".$field."%",$product->$field,$each);
  $each = str_replace("%IFDB_".$field."%","",$each);
  $each = str_replace("%ENDIFDB_".$field."%","",$each);
}
else
{
  $each = preg_replace('/%IFDB_'.$field.'%(.*)%ENDIFDB_'.$field.'%/','',$each);
}

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Tue, 2012-12-18 13:50

Hello David,

Sorry I've got this last one working but both???? in product description an prices?

Thx
Henk

Submitted by support on Tue, 2012-12-18 13:58

Hi Henk,

The sections of code are independent so they shouldn't affect each other - can you let me know a URL where both changes are in place but not working...

Thanks,
David.
--
PriceTapestry.com

Submitted by nanaz on Fri, 2013-10-11 00:07

Hi David,
Just started with PT and I managed to add a couple of new fields to my feeds, which content show up just fine in the standalone version and in the WP plugin, great! I've read the forum threads and implemented the code you supplied to be able to use the IF - ENDIF code in the Main field at the settings page of the WordPress plugin but I just can't get it to work. I replaced:

$each = str_replace("%DB_".$field."%",$product->$field,$each);

in pto_product.php on line 154 with:

if ($product->$field)
{
  $each = str_replace("%DB_".$field."%",$product->$field,$each);
  $each = str_replace("%IFDB_".$field."%","",$each);
  $each = str_replace("%ENDIFDB_".$field."%","",$each);
}
else
{
  $each = preg_replace('/%IFDB_'.$field.'%(.*)%ENDIFDB_'.$field.'%/','',$each);
}

but the IF/ENDIF statements don't work, they only get printed.

Used code in Main field of Wordpress settings:

%IFDB_color%
%DB_color%
%ENDIFDB_color%

Output is:

%IFDB_color%
my colortext
%ENDIFDB_color%

I must be overlooking something, but I just don't know what it is. Hope you can help!

Thank you, Marlies

Submitted by support on Fri, 2013-10-11 08:15

Hello Marlies and welcome to the forum!

The above applies to Prices / Each, but a very similar mod can be made to add %IFDB... support to Price / Main. Also in pto_product.php look for the following code around line 495:

  $html_product = str_replace("%DB_".$field."%",$product->$field,$html_product);

...and REPLACE with:

  if ($product->$field)
  {
    $html_product = str_replace("%DB_".$field."%",$product->$field,$html_product);
    $html_product = str_replace("%IFDB_".$field."%","",$html_product);
    $html_product = str_replace("%ENDIFDB_".$field."%","",$html_product);
  }
  else
  {
    $html_product = str_replace("%DB_".$field."%","",$html_product);
    $html_product = preg_replace('/%IFDB_'.$field.'%(.*)%ENDIFDB_'.$field.'%/','',$html_product);
  }

Cheers,
David.
--
PriceTapestry.com

Submitted by nanaz on Fri, 2013-10-11 12:05

Great, it works like a charm!

Thank you so much David!

Marlies