X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Hide Add to Cart button when a certain Extra Field has a certain value (https://forum.x-cart.com/showthread.php?t=50134)

joannet 10-10-2009 06:50 PM

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

cflsystems 10-10-2009 08:14 PM

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

joannet 10-10-2009 08:35 PM

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.

cflsystems 10-11-2009 06:07 AM

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

ChristineP 10-12-2009 05:50 AM

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.

joannet 10-12-2009 12:20 PM

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.

carpeperdiem 10-12-2009 04:13 PM

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?


All times are GMT -8. The time now is 02:52 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.