I have a pay later gateway that I have set to drop orders into on hold status. I would like to automate sending these orders an email with 'pay now' link when I change their status to pending payment. This would save allot of page load time since I currently have to view order then change status then trigger 'send customer invoice/order details' then drop back to admin order list for each order using this gateway(I do have 'WooCommerce order status manager' which allows me to change order status to pending in bulk editor, but this has a way of confusing me which orders have been sent an invoice with 'pay link' when I get distracted by something that happens in RL, thus if I had it set up to auto send 'pay link' email upon changing to pending status it would cut 95% of the time it takes currently).
I found Send an Email notification to the admin for pending order status in WooCommerce answer code and I'm trying to bend it to my will.
I changed line 11 to contain 'WC_Email_Customer-Invoice" In an attempt to get this code to send that email with a 'pay now' link, Original code pointed to 'WC_Email_New_Order' I realize that the last couple lines appear to only send this to admin email but I haven't been receiving anything in admin email. I'm pretty new to php but I also think this is only targeted at 'NEW Customer Pending Order' and might not pertain to status change to pending. I need this pay later gateway to drop to on-hold so woo will immediately reduce stock of items associated to order, and with this code:
function reduce_stock_pending($order_id) {
wc_reduce_stock_levels($order_id);
}
add_action('woocommerce_order_status_pending', 'reduce_stock_pending');
I'm able to move the order to pending status while nulling the auto restock woo does on orders with pending payment. It's not perfect because u can see in order notes that it rapidly increases stock & then immediately takes it back due to code snippet, but it's functional for my application.
While this whole process is bending vanilla woocommerce functionality that everyone seems to agree holds logic to the average woo store, that same logic does not help with how I need to run my store. The orders pushed through this restricted to local payment gateway will be for products and services that will be delivered and installed before customer account settles the bill.
The struggle continues, I am determined to find a way to automate this despite all the claims that this is only a manual function. Any help in the pursuit of this goal will be greatly appreciated.