Send WooCommerce emails using code – useful for testing custom emails

If you need to test custom WooCommerce checkout email templates or functionality you don’t want to constantly be generating orders, or changing order statuses.

Instead use this snippet to send the emails until your code is working perfectly.

Just add it to your theme functions.php.  Be sure to set the $order_id and the $email_class if necessary.

add_action('init', 'send_wc_email');
function send_wc_email() {

// The order ID we're testing the email with
$order_id = 623;

// The email we want to send
$email_class = 'WC_Email_Customer_Processing_Order';

Available emails are:

// Load the WooCommerce Emails
$wc_emails = new WC_Emails();
$emails = $wc_emails->get_emails();

// Select the email we want & trigger it to send
$new_email = $emails[$email_class];

// Show the email content
echo $new_email->get_content();

How to Show KGs as grams in WooCommerce

The default metric value in WooCommerce is KGs.

My client has been running his site for years in KGs, and many of his products have the weight entered as KGs.

Now he wants to show the value in grams.

WooCommerce has an option to show the weights as grams:

WooCommerce weights

Whilst this changes the label on the website, WooCommerce was still showing the actual weight value in KGs.

I could run a script to change the weights of the products from KGs to grams, but my client was using a CSV export, and I didn’t want to disrupt this.

The following code will display the KG weights as grams on the WooCommerce templates

// Convert the product weight
function ag_woocommerce_product_get_weight( $weight ) {

// Only convert if we have a weight
if ($weight) {

// The weight is in KGS, and we want grams, to multiple by 1000
$weight = $weight * 1000;

return $weight;
// add the filter
add_filter( 'woocommerce_product_get_weight', 'ag_woocommerce_product_get_weight', 10, 1 );

wp_foots() Compromised WordPress and Drupal sites

I’m seeing a few WordPress and Drupal sites with template files being compromised, and a call to a PHP method wp_foots being added

<?php wp_foots();?>

This PHP call injects malicious Javascript code that typically writes spam links to the footer.

It is safe to delete the wp_foots() call. However, this call is part of a bigger compromise, and other PHP files within the website have almost certainly been injected as well.

You should look out for calls to eval(base64_decode( and delete/fix those files.

Dropbox stuck at 100% CPU on Mac, nothing seems to work

If you find your Dropbox is stuck at 100% CPU and constantly ‘Downloading file list’ on your Mac, and you’ve tried all of the unlink/re-link suggestions, be sure to check you don’t have a symbolic link in your Dropbox folders.

I did (from a downloaded website backup), and my Dropbox was stuck synching for weeks.

Run the following from Terminal to search for symbolic links, then delete them (or zip up the folder in my case, then delete the files).

cd ~/Dropbox
find . -type l

Latest from the blog

View All
Social media & sharing icons powered by UltimatelySocial