Year: 2022

WooCommerce Function of the Week: wc_get_logger

Laptop on a log

If you are or aim to be an advanced WooCommerce developer, this week’s WooCommerce function will help you immensely.

And — spoiler alert — that’s not because of this function’s syntax (which is beyond my own understanding), but due to the world of possibility it opens when it’s called from inside a plugin or code snippet.

Logging in software development means keeping a file log of events for troubleshooting and health tracking purposes. Go to WordPress Dashboard > WooCommerce > Status > Logs and take a look at the dropdown: you’ll see dozens if not hundreds of log entries generated by either WooCommerce itself or some of your active WooCommerce extensions.

You can do that too, with wc_get_logger. The wc_get_logger function lets you create your own event log. You might want one for troubleshooting something under development or to give your clients a handy report of what a plugin or code snippet did on any given day.

Not sure why and how you should use wc_get_logger? Here’s more context, some case studies, and a code example. Enjoy!

Read more

WooCommerce Function of the Week: wc_get_customer_total_spent

WooCommerce is full of unknown gems for developers. For example, there are some core functions that calculate pretty complex data, and these functions are mainly “public” so that WooCommerce developers can reuse them for their own purposes.

Today, let’s take a look at the wc_get_customer_total_spent( $user_id ) WooCommerce PHP function.

As you can guess by its name, this function returns the total amount spent by a given customer identified by their user ID. There is no need to loop through user orders to add up totals and return a final sum — WooCommerce already has you covered.

So, let’s take a deeper look at the syntax, meaning, and usage of wc_get_customer_total_spent.

Read more

A2 Hosting
Omnisend
WordPress.com