Add Text Link to Product Page

Hello all,

I’m needing to add a simple text link to the product page to the right of the price. I’ll attach a screenshot for reference. Is this a simple thing or am I looking at a custom mod?





Thanks for any help!

Have a blessed Day.

text link.jpg

Look at common/product_data.tpl and find the price area. You can use a post hook to add your changes.

Add it into line 260 as follows. As you can see where we added “+ Free Shipping!” Just add your href tag…


```php

+ Free Shipping!

```



Haven't figured out the hooks yet. Next on my list. Documentation on how to make hooks make no sense to me.

[quote name='CarStickersDecals' timestamp='1384359210' post='171525']

Add it into line 260 as follows. As you can see where we added “+ Free Shipping!” Just add your href tag…

```php

+ Free Shipping!

```

Haven't figured out the hooks yet. Next on my list. Documentation on how to make hooks make no sense to me.

[/quote]

This will work, but you will lose this customisation if and when you upgrade CS-Cart. To avoid losing your customisations, use hooks…



You will see in /design/themes/yourtheme/templates/common/product_data.tpl that there are many hooks, for example, you'll see this code in CS-Cart V4:-

{hook name="products:prices_block"}

In essence this means use “products” folder and “prices_block.tpl” for creating a hook. In this example:-



Enable “my_changes” addon, create the folders if they do not exist already.

/design/themes/yourtheme/templates/addons/my_changes/products/



In this folder, create the relevant hook file for your custom code:-


prices_block.pre.tpl
prices_block.override.tpl
prices_block.post.tpl




Use “pre” to execute before the {hook} call in /common/product_data.tpl

Use “post” to execute after the {hook} call in /common/product_data.tpl

Use “override” to override (ie. replace) all of the code inside the {hook name=“products:prices_block”}original code here{/hook} tags in /common/product_data.tpl



To clarify, use 'pre' to show your custom code before the {hook}, 'post' for showing your custom code after and 'override' on some special occasions to replace the code within the {hook}…{/hook}.



It is not adviseable to use 'override' for a number of reasons, primarily because if the code within the {hook} call of product_data.tpl is updated in a future CS-Cart version, you will need to update your hook file with the changes, otherwise you run the risk of templates breaking.



Agreed the documentation is pretty horrendous for some areas of CS-Cart including the use of hooks, but once you grasp the concept, you'll love it!

Hey Stellar, Thanks for the info… Starting to make sense… My question is the customization we are implemeting is just after the closing {/hook}. for the prices_block. Will it still work…???

As you can see below the price block code and our edit is below the closing hook.



{********************** Price *********************}
{capture name="price_`$obj_id`"}



{if $show_price_values}
{if $show_price}
{hook name="products:prices_block"}
{if $product.price|floatval || $product.zero_price_action == "P" || ($hide_add_to_cart_button == "Y" && $product.zero_price_action == "A")}
{if $details_page}{/if}{include file="common/price.tpl" value=$product.price span_id="discounted_price_`$obj_prefix``$obj_id`" class="price-num"}
{elseif $product.zero_price_action == "A"}
{assign var="base_currency" value=$currencies[$smarty.const.CART_PRIMARY_CURRENCY]}
{__("enter_your_price")}: {if $base_currency.after != "Y"}{$base_currency.symbol}{/if}test{if $base_currency.after == "Y"}{$base_currency.symbol}{/if}
{elseif $product.zero_price_action == "R"}
{__("contact_us_for_price")}
{assign var="show_qty" value=false}
{/if}
{/hook}
{/if}
{elseif $settings.General.allow_anonymous_shopping == "hide_price_and_add_to_cart" && !$auth.user_id}
{__("sign_in_to_view_price")}
{/if}
+ Free Shipping!

{/capture}
{if $no_capture}
{assign var="capture_name" value="price_`$obj_id`"}
{$smarty.capture.$capture_name nofilter}
{/if}

In this instance, place your custom code in a prices_block.post.tpl in the location as above, ensure my_addons is enabled then clear your site cache.

[quote name='StellarBytes' timestamp='1384370121' post='171541']

In this instance, place your custom code in a prices_block.post.tpl in the location as above, ensure my_addons is enabled then clear your site cache.

[/quote]



First off thanks for your time explaining this as it will help me and others. In the new file I create prices_block.post.tpl do I copy the entire contents of the original file? This is where the confusion comes in… Not sure what goes in the new file. Weather we are just duplicating the original with the mods or just a specific portion. I've been asked this as well and never could give nor get a straight answers…



Someone needs to write a complete comprehensive instruction guide on how to create and modify hooks in relation to cs-cart… Then sell it as an e-book… I'd buy it…

No, the 'pre' and 'post' are supplementary to the file in which the {hook} call is found.



So for example, I create a 'prices_block.pre.tpl' and add only the following code in that file:-

Free Next Day Shipping!

The 'product_data.tpl' file, which contains the {hook} call for this particular template, would then process my custom pre file before the hook.



To make it simpler to understand, here's an example using product_data.tpl. If the original code generated did this:-

```php


{hook name=products:prices_block"}
pricevariable
{/hook}

```
If I use 'pre', I can then have the template generate this:-
```php

Free Next Day Shipping!
£1.00

```
If I use 'post', I can then have the template generate this:-
```php

£1.00
Free Next Day Shipping!

```
And override:-
```php

Free Next Day Shipping!

```

In essence, you can think of it this way:-

Using the 'pre' filename method will replace this part in product_data.tpl:-
```php {hook name="products:prices_block"} ```
Using 'post' filename will replace this part:-
```php {/hook} ```
Using 'override' filename will replace everything in between the opening {hook name...} and the closing {/hook}

Make sense?

I'm getting there. Starting to make sense now. I am going to give it a try. Thank You. Its only taken me 3 years.

Come to find out this does not work at all… If you edit the line in order to add text you loose the ability for your products price to update with product options… Back to the drawing board…

What file(s) did you change and what code did you use?

[quote name='StellarBytes' timestamp='1384458772' post='171621']

What file(s) did you change and what code did you use?

[/quote]



Haven't tried to even implement the hook yet. Just what I posted above… By editing the one line it drops the carts functionality.

Went a whole day not realizing it was screw up.


```php

+ Free Shipping!

```

Try this:-

+ Free Shipping!

Instead of:-

+ Free Shipping!

If it still fails, jQuery doesn't like you. Place it in another just after the closing

Had to go this route and add the second … Thanks for your help. Going to try the hook now.


```php

+ Free Shipping!

```

The issue is that the

must be next to the closing span tag with no spaces or anything else. Just move your “+ Free Shipping” ahead of that comment. The comment is used for the javascript to find the ending tag for the ajax response (it shouldn't need to, but it does). It is the way cs-cart ajax works with result_ids. So your code should look like:

+ Free Shipping!

Thanks Tony, glad to have your wisdom around. Wasn't aware that's what was happening but now I know, it's definitely something useful to prevent having to add even more pointless elements to the DOM.