Use order meta field as trigger

Tagged: ,

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #121648
    webinfluences
    Participant

    Hello,

    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 Yes

    Thanks you for your help

    #121658
    Moshtafizur
    Participant

    Hi 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,
    Moshtafizur

    #121795
    Tom Anbinder
    Moderator
    Plugin Support

    Hi,

    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.

    #122003
    webinfluences
    Participant

    Hello 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 ?

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.