Top WooCommerce & WordPress Plugins › Forums › Custom Emails for WooCommerce › Use order meta field as trigger
- Support forum for the Custom Emails for WooCommerce.
- This topic has 3 replies, 3 voices, and was last updated 1 month, 2 weeks ago by
webinfluences.
- AuthorPosts
-
August 10, 2023 at 9:08 am #121648
webinfluences
ParticipantHello,
We’ve bought your plugin, nice work. Now we have a new need :
Is it possible to use an order meta field as trigger ?
We have a meta field name “Invoice available” > Yes/NO
I would like to send an email “Your invoice is available” once this field is YesThanks you for your help
August 10, 2023 at 11:33 am #121658Hi there,
Thanks for reaching out.
I have escalated this with our development team. They will get back to you as soon as they can.
Kind regards,
MoshtafizurAugust 12, 2023 at 2:48 pm #121795Hi,
We could check the meta each time order is saved – with the
woocommerce_after_order_object_save
action.Try adding this snippet to your site:
add_action( 'woocommerce_after_order_object_save', function ( $order ) { if ( function_exists( 'alg_wc_ce_send_email' ) && 'yes' === $order->get_meta( 'your_meta_key' ) // replace meta key ) { $custom_email_id = 1; // for the "Custom email #1" alg_wc_ce_send_email( $custom_email_id, $order->get_id() ); } } );
Please let me know what you think.
August 17, 2023 at 9:06 am #122003webinfluences
ParticipantHello thanks you for your answer
I’ve paste it in my function.php
// Email when invoice yes add_action( 'woocommerce_after_order_object_save', function ( $order ) { if ( function_exists( 'alg_wc_ce_send_email' ) && 'yes' === $order->get_meta( 'Sage_invoice_File' ) ) { $custom_email_id = 2; // "Custom email #1" alg_wc_ce_send_email( $custom_email_id, $order->get_id() ); } } );
but when i update order, the email #2 is sent even if meta “Sage_invoice_File” is “No”
Do i need to add something else ?
- AuthorPosts
- You must be logged in to reply to this topic.