You are here:  » Adding 'Voucher Code Available' as caption below Product Results

Active Forum Topics


Adding 'Voucher Code Available' as caption below Product Results

Submitted by bat on Wed, 2020-01-01 11:48 in

Happy New Year David!
I was wondering in the product results, is there a way to add a line of text under the read more/more information button to say "Voucher code available" if there's voucher codes available for that particular product, to entice people to click through to see the product page with the full info?

Thanks

Submitted by support on Thu, 2020-01-02 09:36

Hi & Happy New Year!

Sure - if you're using Voucher Codes Integration level 2 (where voucher codes are applied at import time and the voucher_code field populated on the products table) then you can simply add the following PHP section to the top of html/searchresults.php:

<?php
  $ins 
= array();
  foreach(
$searchresults["products"] as $product)
  {
    
$ins[] = "'".database_safe($product["name"])."'";
  }
  
$in implode(",",$ins);
  
$sql "SELECT DISTINCT(name) FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$in.") AND voucher_code <> ''";
  if (
database_querySelect($sql,$rows))
  {
    
$hasVoucherCodes = array();
    foreach(
$rows as $row)
    {
      
$hasVoucherCodes[$row["name"]] = TRUE;
    }
  }
?>

And then within the main loop where the search results for each product are displayed, use something like:

  <?php if (isset($hasVoucherCodes[$product["name"]])): ?>
    <br />Voucher Codes Available!
  <?php endif; ?>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by bat on Thu, 2020-01-02 20:23

Thank you for this! Works a treat.
I was using Voucher Codes integration level 1 - could it still work with that?
I've just temporarily changed it to 2 but if there's a way it can work with 1, then I'd change it back (only cos I update feeds weekly).

Submitted by support on Fri, 2020-01-03 10:06

Hi,

Sure - here's the PHP section for use with level 1 voucher code integration;

<?php
  $ins 
= array();
  foreach(
$searchresults["products"] as $product)
  {
    
$ins[] = "'".database_safe($product["name"])."'";
  }
  
$in implode(",",$ins);
  
$sql "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$in.")";
  
database_querySelect($sql,$rows);
  
$rows tapestry_applyVoucherCodes($rows);
  
$hasVoucherCodes = array();
  foreach(
$rows as $row)
  {
    if (
$row["voucher_code"])
    {
      
$hasVoucherCodes[$row["name"]] = TRUE;
    }
  }
?>

Cheers,
David.
--
PriceTapestry.com