Useful Code Snippets for WooCommerce

Useful Code Snippets for WooCommerce

Heads up: This page may include affiliate links. Read the full disclosure.

WooCommerce is among the most widely used plugins in WordPress to enable eCommerce on a site. Since WooCommerce has filters, actions, and hooks, that means making site changes using code snippets is easy.

Code snippets can easily be added on any connected child site using the MainWP Code Snippets extension.

For example, if you do not have Add to Cart redirect enabled, the Continue Shopping link will redirect the customer back to the product that was added when clicked. In most cases, this does not make sense. You can use this code snippet, which will set the Continue Shopping link to redirect back to the site’s shop page.

If the site is having issues with email being sent out, delayed, or if the checkout is slow, this code snippet will disable deferred transactional emails, enabling WooCommerce emails to be sent out when they happen, and not from a Cron event that is batched out. The change to send emails out on a delayed Cron event was added in version 3.0 of WooCommerce. The delay on emails being sent from WooCommerce is around 10 seconds.

WooCommerce will check that each SKU being used is unique. If an SKU is trying to be used on another product, it will show the SKU is not unique. The unique SKU check-in WooCommerce can be disabled using this code snippet.

If you needed to hide the uncategorized category from the shop page on the front-end of the site, another useful code snippet you can use is this code snippet.

Finally, if you need to make billing fields be required on the checkout page, you can use this code snippet, and modify it by removing the fields not needed.

Looking for something?

Privacy laws apply to businesses that collect personal information. Since no personal information is collected by the MainWP plugins, no privacy laws apply to the MainWP plugins. This includes GDPR, UK DPA 2018, PIPEDA, Australia Privacy Act 1988, LGPD, PIPL, and other privacy laws.
Donata Stroink-Skillrud
Donata Stroink-Skillrud
President of Agency Attorneys

Your Download Is Just One Click Away

…or just download the plugin.

By entering your email, you agree to our Terms of Service and Privacy Policy.