Add an attachment to admin email-notification once order is placed in Woocommerce

前端 未结 1 588
借酒劲吻你
借酒劲吻你 2021-01-16 12:02

I am trying to send a PDF file to shop admin once the new order is placed. The issue with woocommerce_email_attachments hook is that email is sent to both custo

相关标签:
1条回答
  • 2021-01-16 12:29

    The $id is the WC_Email ID that you can use to target a specific email notification like "New order" that is sent to admin when an Order have been successfully placed, this way:

    add_filter( 'woocommerce_email_attachments', 'attach_order_notice', 10, 3 );
    function attach_order_notice ( $attachments, $email_id, $order ) 
    {
        // Only for "New Order" email notification (for admin)
        if( $email_id == 'new_order' ){
            $attachments[] = get_template_directory() . '/notice.pdf';
        }
        return $attachments;
    }
    

    Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

    Tested and working

    0 讨论(0)
提交回复
热议问题