VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: ukfish1 on July 12, 2012, 15:11:44 PM

Title: Remove add to cart button for some products
Post by: ukfish1 on July 12, 2012, 15:11:44 PM
Hi

Is it possible to remove the "add to cart" button for some products only? One of the products we sell cannot be bought directly online. Clients need to call us or email us before we take the order manually.

One possible way round is to set the stock level for this item to zero and then in the general config to select "Displays 'Notify Me' instead of 'Add To Cart' button" against the action to take when an item is out of stock. Is it then possible to remove the "notify me" functionality and button completely (as we are not using stock levels anyway).

cheers

Paul
Title: Re: Remove add to cart button for some products
Post by: ivus on July 18, 2012, 09:57:21 AM

Hi ukfish1,

You sure can. There are however a few steps you need to take to make it all work.

Firstly you need to setup a new CUSTOM FIELD with the following options
Save it and then take note of it's ID (/administrator/index.php?option=com_virtuemart&view=custom&task=edit&virtuemart_custom_id[]=26)

Then in your product detail page find the add to cart block and insert this code:




            $testphoneorder = array();
            foreach ($this->product->customfieldsSorted['normal'] as $phoneorder) :
                $testphoneorder[] = $phoneorder->virtuemart_custom_id;
            endforeach;
           
            if ( ! in_array( 26, $testphoneorder) ) : // <-- insert your ID in place of the 26
           
            // Add To Cart Button
            if (!VmConfig::get('use_as_catalog', 0) and !empty($this->product->prices)) {
               echo $this->loadTemplate('addtocart');
            };
            // Add To Cart Button END
           
            else :


                echo JText::_('COM_VIRTUEMART_CART_NOTIFY');


            endif;



See how you go with that.