Snippets for Classic Commerce

I have set up an area on the Classic Commerce website to start listing useful code snippets for Classic Commerce.

https://classiccommerce.cc/docs/snippets/

These are small pieces of code that add minor functionality without the need for extra plugins. They can be used in either the functions.php file in a child theme, or in a utility plugin that you have created specifically for that purpose.

The idea is similar to the one currently available on the WooCommerce docs…
https://docs.woocommerce.com/documentation/plugins/woocommerce/woocommerce-codex/snippets/

If you have a code snippet that you find useful in CC/WC then post it here and I will add it. Please include a sentence or two about what the snippet does and why it is useful.

8 Likes

This is fantastic!
The official classiccommerce.cc site is very good, looked it over last night. Also, took Classic Commerce for a test spin on a staging site - very fast and very impressed!

I do indeed have useful code snippets for WooCommerce. I will pass them on and you can adapt them for CP and CC functionality.

Keep up the good work! :clap:

PS
( Just sent you a message of the WC snippets we use, so you can choose and share. )

Cheers
Avrom

5 Likes

Hey, thanks Avrom. I’m still tweaking the site but I think it’s getting closer. And great to hear that CC is working well for you.

Thanks also for those code snippets. I’ll go through them and add some to the site.

4 Likes

Your snippet to add the prefix to the $ sign is brilliant (US$, AU$, CA$, etc). I’m surprised that doesn’t come as a fundamental part of WC/CC. Seems like an obvious requirement for any shop selling to multiple countries.

Might be worth adding that as an enhancement request in GitHub.

(also like the redirect shop page one… that’s useful)

2 Likes

Hi Alan,
I’d like to take credit for the currency code, but it was taken from the web. I found lots of developers using that same code snippet. So why write it from scratch?
The only issue I have with it, is it places the currency prefix everywhere. It would be nicer if it was just for subtotals and totals.

The reason it isn’t added to WooCommerce by default, is they can’t up-sell plugins. :wink:

Cheers
Avrom

1 Like

Hey, that’s the same place I get all my code. :wink:

4 Likes

I’ve been looking around the net and finding lots of useful snippets to add to the Classic Commerce collection here: https://classiccommerce.cc/docs/snippets/

The list is currently up to 75! (not bad, considering WooCommerce has a mere 61 on their site :wink:)

They’ve all been tested as working with Classic Commerce on ClassicPress, so if anyone finds any problems with anything please post here.

5 Likes

I’ve been putting an extension together for Classic Commerce and that’s going to be an awesome reference point - thank you for putting it together, that is a massive effort right there :+1:

If anyone testing out Classic Commerce would like to check the extension out and take it for a spin then it can be found here > Extend Commerce - just a few functions at the moment but it’s bound to grow. And apologies for lack of documentation but will get to it as soon as I can.

2 Likes

So this is going to be a plugin that is a collection of useful functions? That’ll be good.

It was actually a really useful exercise for me to find these snippets, learn what they did and test them out. Found a lot of stuff that I can use.

1 Like

Yes very much so. Plus some new ones as Classic Commerce evolves and branches off in a new directions(a personal wish to see new functionality not present in WC) :slight_smile:

2 Likes

Someone asked me about hiding SKUs and I didn’t see this on the list, here they are:

Disable SKUs completely

add_filter('wc_product_sku_enabled', '__return_false');

Hide SKUs in the frontend but keep them in the backend

function pa_hide_skus($enabled){
	if(!is_admin() && is_product()){
		return false;
	}
	return $enabled;
}
add_filter('wc_product_sku_enabled', 'pa_hide_skus');
4 Likes

Thanks Viktor. I’ll add that in.

2 Likes