0

I am trying to send the customer an invoice once an order has been placed, and the user reaches the thankyou page.

I thought i could use the following:

function sendinvoice($orderid)
{
    $email = new WC_Email_Customer_Invoice();
    $email->trigger($orderid);
}   

add_action('woocommerce_thankyou','sendinvoice');

But on the thank you page i then see the following error:

Fatal error: Class 'WC_Email_Customer_Invoice' not found in /***/index.php on line 174

Any ideas on how i can resolve this?

danyo
  • 5,686
  • 20
  • 59
  • 119

2 Answers2

4

it looks you need to specify the full path where 'WC_Email_Customer_Invoice' class is, you could either use require or include, for example: include_once(WP_PLUGIN_DIR . 'woocommerce/includes/emails/class-wc-email-customer-invoice.php');

UPDATE: actually the best way to do it, is using global $woocommerce; and then just call it like this:

WC()->mailer()->emails['WC_Email_Customer_Invoice']->trigger($orderid);

Hope this helps!

David Yee
  • 3,515
  • 25
  • 45
1

You need to include these 2 files;

include_once('../wp-content/plugins/woocommerce/includes/emails/class-wc-email.php');
include_once('../wp-content/plugins/woocommerce/includes/emails/class-wc-email-customer-invoice.php');

UPDATED;

There is another dependent file;

include_once('../wp-content/plugins/woocommerce/includes/libraries/class-emogrifier.php');