Magento: How to disable ‘add to cart’ functionality for certain products
16375
single,single-post,postid-16375,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-5.9,wpb-js-composer js-comp-ver-4.3.4,vc_responsive

Magento: How to disable ‘add to cart’ functionality for certain products

Magento (1)

24 Jul Magento: How to disable ‘add to cart’ functionality for certain products

Magento: How to disable ‘add to cart’ functionality for certain products

Disabling the ‘add to cart’ button in Magento is a lot easier than you think. Initially, I sifted through a lot of useless information and complex workarounds to this problem before I decided to code up a solution myself.

Prerequisites
By following this guide, I’m assuming you have some knowledge with the following things: an understanding of how Magento’s attributes and attribute sets work along with a basic knowledge of customising Magento themes. Finally a basic knowledge of PHP coding to edit the code to suit your needs.

Magento (1)

 Step 1a
The first step of the process is to create an attribute in your Magento admin for the product(s) you want to limit availability to. In order to do this, log into Magento admin and navigate to the Manage Attributes interface, then create a new attribute:

 

From here, you need to create the attribute. For example, I have used instore_only as my attribute code. Below is an example of how I have set mine up, you will need to create your attribute based on your needs.

In the Properties tab:

 In the Manage Label / Options tab:

 After the attribute is configured:

 

Step 1b
From here, we will need to assign our attribute to a group so that we’re able to use it. In order to do this, browse to the Attribute Sets interface and select the set it’ll be going into, normally ‘default':

 

 

From here you’ll be able to insert the newly created attribute into a group. You’ll see the attribute you created under the ‘unassigned attributes’ on the right hand side. Simply drag it into a group, I usually put it at the bottom of the ‘General’ group as this is the first screen you see when adding a new product.

After you’ve put your attribute in the desired group:

Step 2
This step involves inserting a PHP function into your product view template code. You’ll need to navigate to the folder where view.phtml is located:

With view.phtml opened, find the following block of code:

and replace it with the following block of code:

 

What does this bit of code do? Well, in the first PHP if statement we retrieve the instore_only variable and check to see if it is set to yes. If it is set to yes, then we make PHP output a specific bit of code. The echo “”; bit can be edited to whatever you want PHP to do if the value is returned as ‘Yes’. If the value is returned as no, then PHP simply outputs the ‘Add to cart’ box as normal.

That’s all there is to it.

Tags:
, ,
Jenny Tran
hatran260612@gmail.com
No Comments

Post A Comment