I have made a wordpress plugin. It handles a new payment gateway with credit card. After the succesfull transaction I close the order but cannot send email. I tried everything. I tried to call the mailer on init, but it fails on error.log:
PHP Fatal error: Call to a member function get_order_number() on
boolean in
……/wp-content/plugins/woocommerce/includes/emails/class-wc-email-customer-processing-order.php
on line 58
I tried to make a new WC_simplepay();
on init, it fails with class not found.
I tried the same mail sending in the class with new function, and call it from the constructor with $this->functionname();
It works, mail sent, but the payment provider (or me) cannot call this from url (this is why I check the request param), because the class only loads when you are in the checkout page.
I tried the global $woocommerce
… etc solution but also not working in the init part, only inside the class.
Starting of the plugin code:
add_action('plugins_loaded', 'woocommerce_simplepay_init', 0);
function woocommerce_simplepay_init(){
if(!class_exists('WC_Payment_Gateway')) return;
if ($_REQUEST['REFNOEXT']!='')
{
/* .... here are some code regarding the gateway provider ,logging, etc... fully working */
$order_id = explode('_',$_REQUEST['REFNOEXT']);
$order = new WC_Order($order_id[0]);
$order->update_status('processing');
WC()->mailer()->emails['WC_Email_Customer_Processing_Order']->trigger($order_id[0]); // this is generating the error
}
class WC_simplepay extends WC_Payment_Gateway{
public function __construct(){
...
So basically how can I close the order, send email to the customer and handle the provider thingies with this class using remote URL calls?
You are hooking into the wrong action, I recommend you to hook on
init
because it’s executed after all plugins (including woocommerce) has been loaded.But since you’re using a Class, I believe that’s better to include this function inside a class.
Init hook reference