[Skip to main content](#vessel-content)

#   Custom link on product page (with variants)

##

- **[netica](/forum/user/45846-netica "View netica's Profile")**
- [![netica's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/45846-netica "View netica's Profile") Topic Author
- [ Offline](/forum/user/45846-netica)

Less More

- Posts: 17
- Thank you received: 0
-
-

5 years 1 month ago [\#336056](#336056) by [netica](/forum/user/45846-netica "View netica's Profile")  *[Custom link on product page (with variants)](/forum/32-content-creation/903265-custom-link-on-product-page-with-variants#336056 "-- HikaShop version -- : 4.4.3 -- Joomla version -- : 3.9.5 -- PHP version -- : 7.4.14  Hi, I need to make custom link (to demo site) for product and it's variants. What it the better solution: use some standard field or maybe custom field?  I've try do use &quot;product&#95;code&quot; but it shows code in a strange way - while open product page it takes code form php but while switching on variants it takes code from java script (at least that's how I understood the action).  I want to past code to view like it:   class=&quot;butdemo&quot; href=&quot;  mywebiste.com/ element-&gt;product&#95;code; ?&gt;&quot; target=&quot;&#95;blank&quot; rel=&quot;nofollow&quot;&gt;See demo on-line   Thank you in advance Greg")* was created by *[netica](/forum/user/45846-netica "View netica's Profile")*

-- HikaShop version -- : 4.4.3
-- Joomla version -- : 3.9.5
-- PHP version -- : 7.4.14

Hi, I need to make custom link (to demo site) for product and it's variants. What it the better solution: use some standard field or maybe custom field?

I've try do use "product_code" but it shows code in a strange way - while open product page it takes code form php but while switching on variants it takes code from java script (at least that's how I understood the action).

I want to past code to view like it:
&lt;div class="button_cont" align="center"&gt;
&lt;a class="butdemo" href="[ mywebiste.com/](http://mywebiste.com/)&lt;?php echo $this-&gt;element-&gt;product_code; ?&gt;" target="_blank" rel="nofollow"&gt;&lt;span&gt;See demo on-line&lt;/span&gt;&lt;/a&gt;
&lt;/div&gt;

Thank you in advance
Greg

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMyLWNvbnRlbnQtY3JlYXRpb24vOTAzMjY1LWN1c3RvbS1saW5rLW9uLXByb2R1Y3QtcGFnZS13aXRoLXZhcmlhbnRzP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86359
- Thank you received: 14296
-
-

5 years 1 month ago [\#336057](#336057) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Custom link on product page (with variants)](/forum/32-content-creation/903265-custom-link-on-product-page-with-variants#336057 "-- HikaShop version -- : 4.4.3 -- Joomla version -- : 3.9.5 -- PHP version -- : 7.4.14  Hi, I need to make custom link (to demo site) for product and it's variants. What it the better solution: use some standard field or maybe custom field?  I've try do use &quot;product&#95;code&quot; but it shows code in a strange way - while open product page it takes code form php but while switching on variants it takes code from java script (at least that's how I understood the action).  I want to past code to view like it:   class=&quot;butdemo&quot; href=&quot;  mywebiste.com/ element-&gt;product&#95;code; ?&gt;&quot; target=&quot;&#95;blank&quot; rel=&quot;nofollow&quot;&gt;See demo on-line   Thank you in advance Greg")*

Hi,

If it's the same URL with only the product_code being different for each product, you'll want to add your HTML/PHP to the show_default.php view file as a view file override, via the menu Display&gt;Views.
And regarding the product code, you'll want to do something like that : Code:

&lt;?php if(!empty($this-&gt;element-&gt;main)) echo $this-&gt;element-&gt;main-&gt;product_code, else echo $this-&gt;element-&gt;product_code; ?&gt;

Otherwise, for products with variants, $this-&gt;element-&gt;product_code contains the product code of the default variant and not the one of the main product.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMyLWNvbnRlbnQtY3JlYXRpb24vOTAzMjY1LWN1c3RvbS1saW5rLW9uLXByb2R1Y3QtcGFnZS13aXRoLXZhcmlhbnRzP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[netica](/forum/user/45846-netica "View netica's Profile")**
- [![netica's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/45846-netica "View netica's Profile") Topic Author
- [ Offline](/forum/user/45846-netica)

Less More

- Posts: 17
- Thank you received: 0
-
-

5 years 1 month ago [\#336075](#336075) by [netica](/forum/user/45846-netica "View netica's Profile")  Replied by *[netica](/forum/user/45846-netica "View netica's Profile")* on topic *[Custom link on product page (with variants)](/forum/32-content-creation/903265-custom-link-on-product-page-with-variants#336075 "-- HikaShop version -- : 4.4.3 -- Joomla version -- : 3.9.5 -- PHP version -- : 7.4.14  Hi, I need to make custom link (to demo site) for product and it's variants. What it the better solution: use some standard field or maybe custom field?  I've try do use &quot;product&#95;code&quot; but it shows code in a strange way - while open product page it takes code form php but while switching on variants it takes code from java script (at least that's how I understood the action).  I want to past code to view like it:   class=&quot;butdemo&quot; href=&quot;  mywebiste.com/ element-&gt;product&#95;code; ?&gt;&quot; target=&quot;&#95;blank&quot; rel=&quot;nofollow&quot;&gt;See demo on-line   Thank you in advance Greg")*

Thank you for your replay, problem is that your code is not dynamic - it doesn't change while choosing variants (at least on my website).

When I use this code:
&lt;span id="hikashop_product_code_main"&gt;
&lt;?php echo $this-&gt;element-&gt;product_code;?&gt;
&lt;/span&gt;
it works perfectly but don't know how make a link from it. - after switching to variant link is breaking. Also notice that without id="hikashop_product_code_main" it's also not dynamic so it works like your code.

Please look on my site: [ opop.pl/product/43-cosmetica](http://opop.pl/product/43-cosmetica) and try to choose color variant, your code doesn't switch.
I'v put there all 3 codes that we are talking about so can touch the problem.

Ps.: I'm new to HikaShop and made many changes in configuration and few in views... is it possible that I'm the reason ![:)](/media/kunena/emoticons/3.png ":)") ?

Regards
Greg

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMyLWNvbnRlbnQtY3JlYXRpb24vOTAzMjY1LWN1c3RvbS1saW5rLW9uLXByb2R1Y3QtcGFnZS13aXRoLXZhcmlhbnRzP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86359
- Thank you received: 14296
-
-

5 years 1 month ago [\#336077](#336077) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Custom link on product page (with variants)](/forum/32-content-creation/903265-custom-link-on-product-page-with-variants#336077 "-- HikaShop version -- : 4.4.3 -- Joomla version -- : 3.9.5 -- PHP version -- : 7.4.14  Hi, I need to make custom link (to demo site) for product and it's variants. What it the better solution: use some standard field or maybe custom field?  I've try do use &quot;product&#95;code&quot; but it shows code in a strange way - while open product page it takes code form php but while switching on variants it takes code from java script (at least that's how I understood the action).  I want to past code to view like it:   class=&quot;butdemo&quot; href=&quot;  mywebiste.com/ element-&gt;product&#95;code; ?&gt;&quot; target=&quot;&#95;blank&quot; rel=&quot;nofollow&quot;&gt;See demo on-line   Thank you in advance Greg")*

Hi,

My code is fine for what you want as long as you put it somewhere outside of a div with an id finishing by _main in show_default.php
If you add it inside a div with an id finishing by _main, then you have also to make a similar modification in product / show.php where you have a big foreach for the variants of the product to display their own HTML in _variant_xxx divs. And when you change the selected variant, the HTML in the _main divs will be replaced by the HTML in the corresponding _variant_xxx divs. So you want to make the modifications in both places so that the HTML can be replaced with HTML that you modified too.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMyLWNvbnRlbnQtY3JlYXRpb24vOTAzMjY1LWN1c3RvbS1saW5rLW9uLXByb2R1Y3QtcGFnZS13aXRoLXZhcmlhbnRzP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[netica](/forum/user/45846-netica "View netica's Profile")**
- [![netica's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/45846-netica "View netica's Profile") Topic Author
- [ Offline](/forum/user/45846-netica)

Less More

- Posts: 17
- Thank you received: 0
-
-

5 years 1 month ago [\#336094](#336094) by [netica](/forum/user/45846-netica "View netica's Profile")  Replied by *[netica](/forum/user/45846-netica "View netica's Profile")* on topic *[Custom link on product page (with variants)](/forum/32-content-creation/903265-custom-link-on-product-page-with-variants#336094 "-- HikaShop version -- : 4.4.3 -- Joomla version -- : 3.9.5 -- PHP version -- : 7.4.14  Hi, I need to make custom link (to demo site) for product and it's variants. What it the better solution: use some standard field or maybe custom field?  I've try do use &quot;product&#95;code&quot; but it shows code in a strange way - while open product page it takes code form php but while switching on variants it takes code from java script (at least that's how I understood the action).  I want to past code to view like it:   class=&quot;butdemo&quot; href=&quot;  mywebiste.com/ element-&gt;product&#95;code; ?&gt;&quot; target=&quot;&#95;blank&quot; rel=&quot;nofollow&quot;&gt;See demo on-line   Thank you in advance Greg")*

Hi Nicolas, did you look at my webiste? Please notice that your code is now odded outside of a div with an id finishing by _main and it's not changeing while choosing variants. To explain how it's done on example page here is the code:

&lt;p&gt; Hika Support 1st:
&lt;?php
if(!empty($this-&gt;element-&gt;main))
echo $this-&gt;element-&gt;main-&gt;product_code;
else
echo $this-&gt;element-&gt;product_code;
?&gt;
&lt;/p&gt;

&lt;p&gt; Hika Support 2nd:
&lt;?php
echo $this-&gt;element-&gt;product_code;
?&gt;
&lt;/p&gt;

&lt;p&gt;Good one, with id="hikashop_product_code_main"
&lt;span id="hikashop_product_code_main"&gt;
&lt;?php echo $this-&gt;element-&gt;product_code;?&gt;
&lt;/span&gt;
&lt;/p&gt;

Whole problem is that I don't want to use div with an id finishing by _main but only then product code is changing as I want. Hope it's clear now ![;)](/media/kunena/emoticons/24.png ";)")

Regards
Greg

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMyLWNvbnRlbnQtY3JlYXRpb24vOTAzMjY1LWN1c3RvbS1saW5rLW9uLXByb2R1Y3QtcGFnZS13aXRoLXZhcmlhbnRzP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86359
- Thank you received: 14296
-
-

5 years 1 month ago [\#336095](#336095) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Custom link on product page (with variants)](/forum/32-content-creation/903265-custom-link-on-product-page-with-variants#336095 "-- HikaShop version -- : 4.4.3 -- Joomla version -- : 3.9.5 -- PHP version -- : 7.4.14  Hi, I need to make custom link (to demo site) for product and it's variants. What it the better solution: use some standard field or maybe custom field?  I've try do use &quot;product&#95;code&quot; but it shows code in a strange way - while open product page it takes code form php but while switching on variants it takes code from java script (at least that's how I understood the action).  I want to past code to view like it:   class=&quot;butdemo&quot; href=&quot;  mywebiste.com/ element-&gt;product&#95;code; ?&gt;&quot; target=&quot;&#95;blank&quot; rel=&quot;nofollow&quot;&gt;See demo on-line   Thank you in advance Greg")*

Hi,

Well, I thought that you didn't want the product code to change.

If you want the product code of the link to change to the product code of the currently selected variant, then you need to have your code inside of a div with a _main id, and similar code in the product / show.php view file in the corresponding div with the _variant_xxx id. There is no alternative to that.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMyLWNvbnRlbnQtY3JlYXRpb24vOTAzMjY1LWN1c3RvbS1saW5rLW9uLXByb2R1Y3QtcGFnZS13aXRoLXZhcmlhbnRzP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[netica](/forum/user/45846-netica "View netica's Profile")**
- [![netica's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/45846-netica "View netica's Profile") Topic Author
- [ Offline](/forum/user/45846-netica)

Less More

- Posts: 17
- Thank you received: 0
-
-

5 years 1 month ago [\#336156](#336156) by [netica](/forum/user/45846-netica "View netica's Profile")  Replied by *[netica](/forum/user/45846-netica "View netica's Profile")* on topic *[Custom link on product page (with variants)](/forum/32-content-creation/903265-custom-link-on-product-page-with-variants#336156 "-- HikaShop version -- : 4.4.3 -- Joomla version -- : 3.9.5 -- PHP version -- : 7.4.14  Hi, I need to make custom link (to demo site) for product and it's variants. What it the better solution: use some standard field or maybe custom field?  I've try do use &quot;product&#95;code&quot; but it shows code in a strange way - while open product page it takes code form php but while switching on variants it takes code from java script (at least that's how I understood the action).  I want to past code to view like it:   class=&quot;butdemo&quot; href=&quot;  mywebiste.com/ element-&gt;product&#95;code; ?&gt;&quot; target=&quot;&#95;blank&quot; rel=&quot;nofollow&quot;&gt;See demo on-line   Thank you in advance Greg")*

Could you write some example of code in show.php file, please? I don't understand where to put it and how.

As I wrote on my first post maybe it's better to use custom field in my task - what you think about it?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMyLWNvbnRlbnQtY3JlYXRpb24vOTAzMjY1LWN1c3RvbS1saW5rLW9uLXByb2R1Y3QtcGFnZS13aXRoLXZhcmlhbnRzP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86359
- Thank you received: 14296
-
-

5 years 1 month ago [\#336160](#336160) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Custom link on product page (with variants)](/forum/32-content-creation/903265-custom-link-on-product-page-with-variants#336160 "-- HikaShop version -- : 4.4.3 -- Joomla version -- : 3.9.5 -- PHP version -- : 7.4.14  Hi, I need to make custom link (to demo site) for product and it's variants. What it the better solution: use some standard field or maybe custom field?  I've try do use &quot;product&#95;code&quot; but it shows code in a strange way - while open product page it takes code form php but while switching on variants it takes code from java script (at least that's how I understood the action).  I want to past code to view like it:   class=&quot;butdemo&quot; href=&quot;  mywebiste.com/ element-&gt;product&#95;code; ?&gt;&quot; target=&quot;&#95;blank&quot; rel=&quot;nofollow&quot;&gt;See demo on-line   Thank you in advance Greg")*

Hi,

In show_default, you have this code by default: Code:

&lt;span id="hikashop_product_code_main" class="hikashop_product_code_main"&gt;&lt;?php echo $this-&gt;element-&gt;product_code; ?&gt;&lt;/span&gt;

So I suppose you want to replace it with: Code:

&lt;span id="hikashop_product_code_main" class="hikashop_product_code_main"&gt; &lt;div class="button_cont" align="center"&gt; &lt;a class="butdemo" href=" mywebiste.com/ &lt;?php echo $this-&gt;element-&gt;product_code; ?&gt;" target="_blank" rel="nofollow"&gt;&lt;span&gt;See demo on-line&lt;/span&gt;&lt;/a&gt; &lt;/div&gt; &lt;/span&gt;

In the product / show.php view file you can see this code: Code:

&lt;div id="hikashop_product_code_&lt;?php echo $variant_name; ?&gt;" style="display:none;"&gt;&lt;?php echo $variant-&gt;product_code; ?&gt;&lt;/div&gt;

So I suppose you want to replace it with: Code:

&lt;div id="hikashop_product_code_&lt;?php echo $variant_name; ?&gt;" style="display:none;"&gt; &lt;div class="button_cont" align="center"&gt; &lt;a class="butdemo" href=" mywebiste.com/ &lt;?php echo $variant-&gt;product_code; ?&gt;" target="_blank" rel="nofollow"&gt;&lt;span&gt;See demo on-line&lt;/span&gt;&lt;/a&gt; &lt;/div&gt;&lt;/div&gt;

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMyLWNvbnRlbnQtY3JlYXRpb24vOTAzMjY1LWN1c3RvbS1saW5rLW9uLXByb2R1Y3QtcGFnZS13aXRoLXZhcmlhbnRzP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[netica](/forum/user/45846-netica "View netica's Profile")**
- [![netica's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/45846-netica "View netica's Profile") Topic Author
- [ Offline](/forum/user/45846-netica)

Less More

- Posts: 17
- Thank you received: 0
-
-

5 years 3 weeks ago [\#336359](#336359) by [netica](/forum/user/45846-netica "View netica's Profile")  Replied by *[netica](/forum/user/45846-netica "View netica's Profile")* on topic *[Custom link on product page (with variants)](/forum/32-content-creation/903265-custom-link-on-product-page-with-variants#336359 "-- HikaShop version -- : 4.4.3 -- Joomla version -- : 3.9.5 -- PHP version -- : 7.4.14  Hi, I need to make custom link (to demo site) for product and it's variants. What it the better solution: use some standard field or maybe custom field?  I've try do use &quot;product&#95;code&quot; but it shows code in a strange way - while open product page it takes code form php but while switching on variants it takes code from java script (at least that's how I understood the action).  I want to past code to view like it:   class=&quot;butdemo&quot; href=&quot;  mywebiste.com/ element-&gt;product&#95;code; ?&gt;&quot; target=&quot;&#95;blank&quot; rel=&quot;nofollow&quot;&gt;See demo on-line   Thank you in advance Greg")*

Hi, Nicolas, thak you very much. Code solved the problem.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMyLWNvbnRlbnQtY3JlYXRpb24vOTAzMjY1LWN1c3RvbS1saW5rLW9uLXByb2R1Y3QtcGFnZS13aXRoLXZhcmlhbnRzP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.074 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
