Changing A Button's Text

Hi,

I want to change a button's text (e.g: Add to cart button or something else) according to database query result.

For example;



{if [b]fn_get_stock_count/b > 0}

{include file=“buttons/button.tpl” but_text=ADD_TO_CART but_name=$but_name …

{else}

{include file=“buttons/button.tpl” but_text=PRE_ORDER but_name=$but_name …

{/if}



Result: if stock count is less than 0, “PRE ORDER”. If not “ADD TO CART”



is there any function like fn_get_stock_count? or do you know how can I do that?



Thank you so much…

I found the solution,

there is no need to use any fn_get_… function. You are able to get the product amount by using product.amount already. If you are trying to make “Pre Order”, it is so simple!


  • First, add a language variable from control panel to change “add_to_cart” button's text to Pre Order. When you check “buy in advance” option and set the product amount 0 or less, the button's text will be change.
  • Second, allow negative stock amounts
  • Finally change the “add_to_cart.tpl” like below.



    {hook name=“products:add_to_cart”}

    {assign var=“c_url” value=$config.current_url|escape:url}

    {if $settings.General.allow_anonymous_shopping == “Y” || $auth.user_id}

    [color=“#8B0000”]{if $product.amount > 0}[/color]

    {include file=“buttons/button.tpl” but_id=$but_id but_text=$but_text|default:[color=“#8B0000”]$lang.add_to_cart[/color] but_name=$but_name but_onclick=$but_onclick but_href=$but_href but_target=$but_target but_role=$but_role|default:“text”}

    [color=“#8B0000”]{else}[/color]

    {include file=“buttons/button.tpl” but_id=$but_id but_text=$but_text|default:$[color=“#8B0000”]lang.pre_order[/color] but_name=$but_name but_onclick=$but_onclick but_href=$but_href but_target=$but_target but_role=$but_role|default:“text”}

    [color=“#8B0000”]{/if}[/color]

    {else}

    {$lang.text_login_to_add_to_cart}





    {if $controller == “auth” && $mode == “login_form”}

    {assign var=“login_url” value=$config.current_url}

    {else}

    {assign var=“login_url” value=“auth.login_form?return_url=$c_url”}

    {/if}



    {include file=“buttons/button.tpl” but_id=$but_id but_text=$lang.sign_in_to_buy but_href=$login_url but_role=$but_role|default:“text” but_name=“”}

    {/if}

    {/hook}