A simple, powerful and independent e-commerce platform.
Sell anything with ease.

How to add code snippets to Classic Commerce

How to add code snippets to Classic Commerce

Code snippets are a great way to add minor functionality or make small modifications to your Classic Commerce site without the need for extra plugins. The best way to use code snippets is to put them in a separate plugin that is added to your site, specifically for this purpose. They could also be added to the functions.php file in your child theme, but if you ever change your theme these will get lost. Having them located in their own dedicated plugin makes it much cleaner and more manageable.

Making a snippets plugin is easier than you think!

  1. Download the sample plugin here:  cc-snippets.zip
  2. Add it to your site in the usual way – you can either use the plugin installer in your ClassicPress admin area, or unzip it and copy it into your plugins folder manually using an ftp program like FileZilla.
  3. Activate the plugin.

The sample plugin comes with some examples included.  It has code snippets to hide related products and additional information, as well as ones for removing the ordering dropdown box, breadcrumbs and the result count.

You will need to use ftp to edit this file. Just delete the snippets you don’t want, and then copy and paste in any examples you may need, using the index page provided here: https://classiccommerce.cc/docs/snippets/

Note that some snippets will need some customising, so have a look at the code and make any edits necessary to suit your particular scenario.

For example, the “Set a minimum order quantity for checkout” snippet has this in the code:

function cc_minimum_order_quantity() {
// Set this variable to specify a minimum order quantity
$minimum = 12;

… so you will need to change this to the amount you want to set as your minimum order.

Of course you should always take a backup of your site before you start. Then make changes gradually and check each one to see that it has the desired result.

Photo by Clément H on Unsplash