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.
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 } ?>
Custom OpenCart modules and solutions. You can write PM with additional questions... Extensions you can find here
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Hi, thanks for the quick reply.kestas wrote: ↑Mon Dec 18, 2017 2:47 amHi,
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 } ?>
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
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
"Size" is a Select, "Color" is a Radio. Or I didn't understand the question.straightlight wrote: ↑Mon Dec 18, 2017 3:08 amGood. Now, from which option type in product.tpl file are you adding this code?
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
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.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Users browsing this forum: No registered users and 205 guests