Email Woocommerce静态电子邮件附件

Email Woocommerce静态电子邮件附件,email,woocommerce,Email,Woocommerce,有没有办法将静态pdf文件附加到我所有的woocommerce订单完整电子邮件中?通过woocommerce 3.5.4测试正常 add_filter('woocommerce_email_attachments', 'attach_terms_conditions_pdf_to_email', 10, 3); function attach_terms_conditions_pdf_to_email($attachments, $id, $object) { $your_pdf_p

有没有办法将静态pdf文件附加到我所有的woocommerce订单完整电子邮件中?

通过woocommerce 3.5.4测试正常

add_filter('woocommerce_email_attachments', 'attach_terms_conditions_pdf_to_email', 10, 3);

function attach_terms_conditions_pdf_to_email($attachments, $id, $object) {

    $your_pdf_path = 'https://smagdansk.dk/wp-content/uploads/2018/08/SMAGdansk-Fortrydelsesformular.pdf';

    if (!class_exists('WP_Http'))
        include_once( ABSPATH . WPINC . '/class-http.php' );
    $http = new WP_Http();
    $response = $http->request($your_pdf_path);
    if ($response['response']['code'] != 200) {
        return false;
    }
    $upload = wp_upload_bits(basename($your_pdf_path), null, $response['body']);
    if (!empty($upload['error'])) {
        return false;
    }
    $file_path = $upload['file'];


    $attachments[] = $file_path;
    return $attachments;
}

我是否要将其添加到functions.php中,因为当我这样做时,它会显示:未捕获错误:调用wp content/themes/oceanwp/functions.php:1110 Stack trace:#0 wp settings.php(443):include()#1 wp config.php(90):require_once('/home/u1fnhv5/w…)#2 wp load.php(37):require#once('/home/u1fnhv5/w…)#3 wp admin/admin.php(31):require_once('/home/u1fnhv5/w…)#4 wp admin/theme editor.php(10):require_once('/home/u1fnhv5/w…)#5{main}在dd_过滤器前漏掉字母a。是的,将其添加到function.php