Jump to content

Sold Out Button


Nathum

Recommended Posts

Hi,

 

I got sick of having Order Now on products that are sold out. So here is somecode I would like to share, hopefully WHMCS add it.

 

 

Around Line 75 in \whmcs\templates\orderforms\modern

 

<a href="cart.php?a=add&{if $product.bid}bid={$product.bid}{else}pid={$product.pid}{/if}" class="btn btn-success btn-lg {if $product.qty lt '1'} btn-danger disabled{/if}"><i class="fa fa-shopping-cart"></i>  {if $product.qty lt '1'} Sold Out{else}{$LANG.ordernowbutton} {/if}</a>

 

Screenshot

1444830616.jpg

Link to comment
Share on other sites

  • 2 weeks later...
This code is safe for using? I mean if it create any security issue then?

looks perfectly safe for me - it's just modifying the button based on stock level.

 

if it were me, i'd prefer it to use a Language entry instead of "Sold Out"... otherwise every user will see "Sold Out" in English regardless of their language choice.

 

<a href="cart.php?a=add&{if  $product.bid}bid={$product.bid}{else}pid={$product.pid}{/if}" class="btn  btn-success btn-lg {if $product.qty lt '1'} btn-danger  disabled{/if}"><i class="fa fa-shopping-cart"></i>  {if  $product.qty lt '1'} {$LANG.outofstock}{else}{$LANG.ordernowbutton}  {/if}</a>

 

then if you need to change "Out of Stock" to "Sold Out" you can use a language override for each language.

 

(Better If someone from mod or developer check this code then it will be very helpful for me, Also I want to display sold out instead of "available 0" ;)

"Available 0" doesn't show on my v6 dev - it will show the stock level if it's not zero, but that would be very simple to change it the template.

Link to comment
Share on other sites

  • 5 weeks later...
  • 1 month later...

in standard_cart/products.tpl, you could change...

 

                                    <a  href="cart.php?a=add&{if  $product.bid}bid={$product.bid}{else}pid={$product.pid}{/if}" class="btn  btn-success btn-sm" id="product{$product@iteration}-order-button">
                                       <i class="fa fa-shopping-cart"></i>
                                       {$LANG.ordernowbutton}
                                   </a>

to...

 

                                    <a href="cart.php?a=add&{if $product.bid}bid={$product.bid}{else}pid={$product.pid}{/if}" class="btn btn-sm {if $product.qty lt '1'}btn-danger disabled{else}btn-success{/if}" id="product{$product@iteration}-order-button">
                                       <i class="fa fa-shopping-cart"></i>
                                       {if $product.qty lt '1'} {$LANG.outofstock}{else}{$LANG.ordernowbutton}{/if}
                                   </a>

that would replace the "Order Now" button with an "Out of Stock" disabled button if the stock level of that product is less than 1. (and assuming you've created the language override for outofstock).

 

80ypl27.png

Link to comment
Share on other sites

in standard_cart/products.tpl, you could change...

 

                                    <a  href="cart.php?a=add&{if  $product.bid}bid={$product.bid}{else}pid={$product.pid}{/if}" class="btn  btn-success btn-sm" id="product{$product@iteration}-order-button">
                                       <i class="fa fa-shopping-cart"></i>
                                       {$LANG.ordernowbutton}
                                   </a>

to...

 

                                    <a href="cart.php?a=add&{if $product.bid}bid={$product.bid}{else}pid={$product.pid}{/if}" class="btn btn-sm {if $product.qty lt '1'}btn-danger disabled{else}btn-success{/if}" id="product{$product@iteration}-order-button">
                                       <i class="fa fa-shopping-cart"></i>
                                       {if $product.qty lt '1'} {$LANG.outofstock}{else}{$LANG.ordernowbutton}{/if}
                                   </a>

that would replace the "Order Now" button with an "Out of Stock" disabled button if the stock level of that product is less than 1. (and assuming you've created the language override for outofstock).

 

80ypl27.png

 

it changed all to "Out of Stock"

Link to comment
Share on other sites

it changed all to "Out of Stock"

that might occur if you have not enabled stock control on the product(s). :roll:

 

try using the following code instead, it will now do two checks - first to see whether stock control is enabled on the product, and if so, then check if the qty value is less than 1... if both are true, the item is out of stock and the red disabled button is shown; otherwise the order now button will be displayed.

 

                                    <a href="cart.php?a=add&{if $product.bid}bid={$product.bid}{else}pid={$product.pid}{/if}" class="btn btn-sm {if $product.qty neq '' and $product.qty lt 1}btn-danger disabled{else}btn-success{/if}" id="product{$product@iteration}-order-button">
                                       <i class="fa fa-shopping-cart"></i>
                                       {if $product.qty neq '' and $product.qty lt 1}{$LANG.outofstock}{else}{$LANG.ordernowbutton}{/if}
                                   </a>

Link to comment
Share on other sites

It is showing "order now" for 0 quantity product too

not for me - if stock control is enabled and the qty value is 0 (or less), it's showing "Out of Stock"; if you change the value to anything greater than 0, it shows the "Order Now" button - as it does when stock control is disabled.

 

if you're seeing something different, then I might need to see screenshots of the client area output and also the product details settings.

Link to comment
Share on other sites

how strange... :?:

 

try putting the value back in single quotes again...

 

<a href="cart.php?a=add&{if $product.bid}bid={$product.bid}{else}pid={$product.pid}{/if}" class="btn btn-sm {if $product.qty neq '' and $product.qty lt '1'}btn-danger disabled{else}btn-success{/if}" id="product{$product@iteration}-order-button">
                                       <i class="fa fa-shopping-cart"></i>
                                       {if $product.qty neq '' and $product.qty lt '1'}{$LANG.outofstock}{else}{$LANG.ordernowbutton}{/if}
                                   </a>  

Link to comment
Share on other sites

how strange... :?:

 

try putting the value back in single quotes again...

 

<a href="cart.php?a=add&{if $product.bid}bid={$product.bid}{else}pid={$product.pid}{/if}" class="btn btn-sm {if $product.qty neq '' and $product.qty lt '1'}btn-danger disabled{else}btn-success{/if}" id="product{$product@iteration}-order-button">
                                       <i class="fa fa-shopping-cart"></i>
                                       {if $product.qty neq '' and $product.qty lt '1'}{$LANG.outofstock}{else}{$LANG.ordernowbutton}{/if}
                                   </a>  

 

 

Still same issue

Link to comment
Share on other sites

Still same issue

can you add {debug} to the end of the products.tpl template and save, refresh the page in the browser and you should get a popup window.

 

in that window, scroll down to $products and find the entry for PH-NM02 and the qty value - take a screenshot of that part of the popup... or copy&paste the whole popup and PM it to me.

 

btw - have you tried changing lt '1' to eq '0' ?

Link to comment
Share on other sites

can you add {debug} to the end of the products.tpl template and save, refresh the page in the browser and you should get a popup window.

 

in that window, scroll down to $products and find the entry for PH-NM02 and the qty value - take a screenshot of that part of the popup... or copy&paste the whole popup and PM it to me.

 

btw - have you tried changing lt '1' to eq '0' ?

 

pm sent.

Yes tested with eq '0' still same issue

Link to comment
Share on other sites

  • 1 year later...

following a recent PM conversation with another member, I now think the correct code should be...

 

            <a href="cart.php?a=add&{if $product.bid}bid={$product.bid}{else}pid={$product.pid}{/if}" class="btn btn-sm {if $product.qty > 0 or !is_numeric($product.qty)}btn-success{else}btn-danger disabled{/if}"  id="product{$product@iteration}-order-button">
           <i class="fa fa-shopping-cart"></i>
           {if $product.qty > 0 or !is_numeric($product.qty)}{$LANG.ordernowbutton}{else}{$LANG.outofstock}{/if}
           </a>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated