Magento allow only certain products to continue with checkout

Posted on March 31, 2014

So like always, i have a client who needs to have it so the customer can only continue to the checkout and finish it if they have certain products in their cart. this is in magento 1.7 but i don’t see why it wont work with the latest version.

First you need to create a new product attribute and assign it to the attribute sets your using in your magento.

In this example i have created my new attribute with the attribute code or allowcheckout and i have made it a type of Yes/No.

now once you have that go and edit some products and assign them to Yes for this new attribute so you can do some testing to see if it works after we add the following code.

find this file to edit: /app/design/frontend/*yourdesignpackage*/*yourtheme*/template/checkout/cart.phtml

if it is not there copy it over from your base/default theme.

just before the form tag or directly below this code:

add this code:

so this displays a message at the top of the cart if no items in your current have that new attribute set to yes.

now down the page find this code:

and before it add this:

and then find the closing </ul> tag a few lines down and add this below it:

save and test it.

but now we have to actually restrict the checkout page in case they get linked directly to it.

I am using one page checkout here, be the same principle for the multi checkout.

edit this file: /app/design/frontend/*yourdesignpackage*/*yourtheme*/template/checkout/onepage.phtml

just under the title closing </div> and this code :

and at the very end of the file add this: