You are here:  » Multi Link Buy Button


Multi Link Buy Button

Submitted by ChrisNBC on Thu, 2017-05-18 16:42 in

Hi David,

Seems like a while since I last posted...hope all is going well.

I wondered if you might be able to help me add some logic for the main ‘buy’ button I have on my product page….

Currently, I have a main ‘above the fold’ ‘buy’ button on the product page. When it’s clicked the page moves to the main price table which has ‘buy buttons’ alongside each listed product. Increasingly, I have noticed the ‘price table’ contains multiple rows for only a single merchant showing each unique price and size. However even if the price table contains multiple sizes/prices the merchants provides the same deep link. I would like to add some logic to the ‘above the fold’ buy button so that if there is only one merchant listed in the price table, the button links directly to the merchants deep link (via jump.php) as normal, but if there is more than one merchant it will still move the user to the price table to select the merchant.

For the ‘above the fold’ button, I’m currently using the code:

<a class="btn btn-primary_goto" href="#prod_price-tbl"><?php print translate("Buy NOW "); ?><span class="glyphicon glyphicon-shopping-cart"></span></a>

Thanks in advance.

Best regards
Chris

Submitted by support on Fri, 2017-05-19 08:40

Hi Chris,

Sure - have a go with something like this;

<?php
  $merchants = array();
  foreach($product["products"] as $p)
  {
    $merchants[$p["merchant"]] = TRUE;
  }
  if (count($merchants)==1)
  {
    $href = tapestry_buyURL($product["products"][0]);
  }
  else
  {
    $href = "#prod_price-tbl";
  }
?>
<a class="btn btn-primary_goto" href="<?php print $href?>"><?php print translate("Buy NOW "); ?><span class="glyphicon glyphicon-shopping-cart"></span></a>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Fri, 2017-05-19 22:21

Thanks David,

The code above works perfectly.

Best regards
Chris