Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Hide Add to Cart button when a certain Extra Field has a certain value

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 10-10-2009, 06:50 PM
 
joannet joannet is offline
 

Senior Member
  
Join Date: Mar 2006
Posts: 105
 

Default Hide Add to Cart button when a certain Extra Field has a certain value

Working on v4.2.2 here.

I've set up an Extra Field (Special is it's name).

The value of this field can be Yes or No.

If this field is set to Yes, the Add to Cart button should be hidden so customers cannot purchase the product.

I have tried various things on customer/main/product.tpl, but have had no luck.

e.g. {if $v.active eq "Y" && $v.field eq "Special" && $v.field_value eq "No"}add to cart code here{/if}

Adding this to the product.tpl hides the add to cart button on all product pages, whether the 'Special' extra field is set to Yes or No.

Any help would be most appreciated.

Thanks
__________________
/joannet/
X-Cart version 4.1.9 and above
Reply With Quote
  #2  
Old 10-10-2009, 08:14 PM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,201
 

Default Re: Hide Add to Cart button when a certain Extra Field has a certain value

{if $product.extra_fields[0].value ne "Yes"} button code here {/if}
replace number [0] with your fields number in the array
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #3  
Old 10-10-2009, 08:35 PM
 
joannet joannet is offline
 

Senior Member
  
Join Date: Mar 2006
Posts: 105
 

Default Re: Hide Add to Cart button when a certain Extra Field has a certain value

Thanks Steve, but no luck with that code unfortunately.

The button code is showing on all products still.
__________________
/joannet/
X-Cart version 4.1.9 and above
Reply With Quote
  #4  
Old 10-11-2009, 06:07 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,201
 

Default Re: Hide Add to Cart button when a certain Extra Field has a certain value

Try {if $product.extra_fields.0.value ne "Yes"} button code here {/if}
again replace 0 with your field number
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #5  
Old 10-12-2009, 05:50 AM
 
ChristineP ChristineP is offline
 

eXpert
  
Join Date: Jul 2008
Posts: 310
 

Default Re: Hide Add to Cart button when a certain Extra Field has a certain value

I've been able to work with Extra fields in v4.1.9 with using the loop through. I haven't upgraded to v4.2, so there may be different variable names needed.

{section name=field loop=$extra_fields}
{if $extra_fields[field].service_name eq "Special" && $extra_fields[field].field_value eq "No"} 
{elseif $extra_fields[field].service_name eq "Special" && $extra_fields[field].field_value eq "Yes"}
{include file="buttons/add_to_cart.tpl" style="button" href="javascript: if(FormValidation()) document.orderform.submit();"}
{/if}
{/section}

If this doesn't work, you may need to create a .tpl to place in your Extra_Fields folder and use the include to call out the loop through for the product.tpl.
__________________
______________
version 4.1.9 Gold
Reply With Quote
  #6  
Old 10-12-2009, 12:20 PM
 
joannet joannet is offline
 

Senior Member
  
Join Date: Mar 2006
Posts: 105
 

Default Re: Hide Add to Cart button when a certain Extra Field has a certain value

Thanks for your advice Christine. Unfortunately it is still not working.

I will post back once I have the solution.
__________________
/joannet/
X-Cart version 4.1.9 and above
Reply With Quote
  #7  
Old 10-12-2009, 04:13 PM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default Re: Hide Add to Cart button when a certain Extra Field has a certain value

A checkbox (extra field) will either return content or not, not yes or no -- right?

SO --- try this:

{if $extra_fields[field].field eq "special" && $extra_fields[field].field_value eq ""}add to cart code here{/if}

that is: if the special filed is not checked (it's empty), show the cart code. if the special box is checked (or has any content) the add to cart code will not display.

I use 4.1.9 and this code works for me. I also use a checkbox for an extra field. Try it?
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 03:41 PM.

   

 
X-Cart forums © 2001-2020