Post by Vindojeens » Mon Dec 18, 2017 2:31 am

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.

Newbie

Posts

Joined
Sun Nov 20, 2016 12:49 am

Post by kestas » 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 } ?>
Last edited by kestas on Mon Dec 18, 2017 2:47 am, edited 1 time in total.

Custom OpenCart modules and solutions. You can write PM with additional questions... Extensions you can find here


Active Member

Posts

Joined
Tue Oct 12, 2010 2:23 am

Post by straightlight » Mon Dec 18, 2017 2:47 am

OC version posted. Although, no file location posted where this code is being edited for. No BBCodes or file attachment found.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Vindojeens » Mon Dec 18, 2017 2:58 am

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

Newbie

Posts

Joined
Sun Nov 20, 2016 12:49 am

Post by straightlight » Mon Dec 18, 2017 3:03 am

What is the file location?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Vindojeens » Mon Dec 18, 2017 3:06 am

EDIT: Link removed.
Last edited by Vindojeens on Mon Dec 18, 2017 3:22 am, edited 1 time in total.

Newbie

Posts

Joined
Sun Nov 20, 2016 12:49 am

Post by straightlight » Mon Dec 18, 2017 3:08 am

Good. 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


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Vindojeens » Mon Dec 18, 2017 3:11 am

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. :(
Last edited by Vindojeens on Mon Dec 18, 2017 3:13 am, edited 1 time in total.

Newbie

Posts

Joined
Sun Nov 20, 2016 12:49 am

Post by straightlight » Mon Dec 18, 2017 3:13 am

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?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Vindojeens » Mon Dec 18, 2017 3:17 am

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.

Newbie

Posts

Joined
Sun Nov 20, 2016 12:49 am

Post by straightlight » Mon Dec 18, 2017 3:22 am

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!)

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 205 guests