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
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
Sorry Henk, that line should be:
$each = preg_replace('/%IFDB_'.$field.'%(.*)%ENDIFDB_'.$field.'%/','',$each);
Cheers,
David.
--
PriceTapestry.com
No problem David,
But now the originals are:
Levertijd: %DB_levertijd%
Verzendkosten: %DB_verzendkosten%
Voorraad:
Thx
Henk
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
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
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
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
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
Hello David,
Sorry I've got this last one working but both???? in product description an prices?
Thx
Henk
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
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);
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
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
Great, it works like a charm!
Thank you so much David!
Marlies
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