Page 1 of 1
Display custom link on product page?
Posted: Mon Dec 18, 2017 2:31 am
by Vindojeens
Hey there,
I have a question.
I want to add a custom link on my product page for some products (not all).
This link hast to show up if a product has a certain option.
For example:
The product is a woman's dress.
This is the code I came up with myself:
<?php if ($option['name'] == 'Size') { ?> <?php echo '<a href="https://........">Link Text</a><br></br>'; ?>
<?php } ?>
This works if the dress has only one option (like "Size")....the link shows alright.
But if I add another option to the dress (like "Color") the link doesn't show up anymore.
I tried:
<?php if ($option['name'] == 'Size' AND $option['name'] == 'Color') { ?> <?php echo '<a href="https://........">Link Text</a><br></br>'; ?>
<?php } ?>
But it too didn't work.
I don't know why.
Can someone please help?
Thanks
EDIT: I use Opencart 2.3.0.2.
Re: Display custom link on product page?
Posted: Mon Dec 18, 2017 2:47 am
by kestas
Hi,
you use not right logical operation. you should use OR (||) instead AND (&&). I assume you need to show when option are size or color o both.
like this:
Code: Select all
<?php if ($option['name'] == 'Size' || $option['name'] == 'Color') { ?> <?php echo '<a href="https://........">Link Text</a><br></br>'; ?>
<?php } ?>
Re: Display custom link on product page?
Posted: Mon Dec 18, 2017 2:47 am
by straightlight
OC version posted. Although, no file location posted where this code is being edited for. No BBCodes or file attachment found.
Re: Display custom link on product page?
Posted: Mon Dec 18, 2017 2:58 am
by Vindojeens
kestas wrote: ↑Mon Dec 18, 2017 2:47 am
Hi,
you use not right logical operation. you should use OR (||) instead AND (&&). I assume you need to show when option are size or color o both.
like this:
Code: Select all
<?php if ($option['name'] == 'Size' || $option['name'] == 'Color') { ?> <?php echo '<a href="https://........">Link Text</a><br></br>'; ?>
<?php } ?>
Hi, thanks for the quick reply.
I tried your code (using OR). It now shows in dresses, but it also shows on all other products that have the "Color" options like pencils and watches that don't have the "Size" option, but have the "Color" option.
Basically I need to show the link ONLY on products that have the "Size" option (among others).
For example:
Link must show on:
Dresses
Options: Size, Color
Link must NOT show on:
Watches
Options: Belt material, Color
Re: Display custom link on product page?
Posted: Mon Dec 18, 2017 3:03 am
by straightlight
What is the file location?
Re: Display custom link on product page?
Posted: Mon Dec 18, 2017 3:06 am
by Vindojeens
EDIT: Link removed.
Re: Display custom link on product page?
Posted: Mon Dec 18, 2017 3:08 am
by straightlight
Good. Now, from which option type in product.tpl file are you adding this code?
Re: Display custom link on product page?
Posted: Mon Dec 18, 2017 3:11 am
by Vindojeens
straightlight wrote: ↑Mon Dec 18, 2017 3:08 am
Good. Now, from which option type in product.tpl file are you adding this code?
"Size" is a Select, "Color" is a Radio. Or I didn't understand the question.

Re: Display custom link on product page?
Posted: Mon Dec 18, 2017 3:13 am
by straightlight
Then, no, you did not understood the question; which is why the code you attempt to add fails to load as intended. You are adding the codes to a specific location on the product options from product.tpl file on the store-front end. From which paragraph are you adding these codes specifically?
Re: Display custom link on product page?
Posted: Mon Dec 18, 2017 3:17 am
by Vindojeens
Only in this one place. Line 329 and 330. It is roughly the place I need it to show on my frontend.
Sorry I'm a noob, I have no idea what you mean.
EDIT: I got it now, you were right I added it in the wrong place. It must be under the paragraph defining "SELECT" as this option is a SELECT.
Thanks a lot! You really helped me.
Re: Display custom link on product page?
Posted: Mon Dec 18, 2017 3:22 am
by straightlight
More information is needed than line numbers since you might be using a custom theme. Can you post the entire section in BBCode of where you are adding the code? (Not the entire file!)