• add_filter('woocommerce_email_attachments', 'add_flexible_checkout_fields_attachments_to_vendor_email', 10, 3);

    function add_flexible_checkout_fields_attachments_to_vendor_email($attachments, $email_id, $order) {
    if ($email_id === 'new_order') {
    $order_id = $order->get_id();
    $uploaded_files = get_post_meta($order_id, '_billing_datei_upload', true);
    if (!empty($uploaded_files)) {
    if (is_string($uploaded_files)) {
    $uploaded_files = explode(',', $uploaded_files);
    }
    if (is_array($uploaded_files)) {
    foreach ($uploaded_files as $file) {
    $file_path = get_attached_file($file);
    if ($file_path && file_exists($file_path)) {
    $attachments[] = $file_path;
    }
    }
    } else {
    $file_path = get_attached_file($uploaded_files);
    if ($file_path && file_exists($file_path)) {
    $attachments[] = $file_path;
    }
    }
    }
    }

    return $attachments;
    }

    I used this code, but there are sometimes files attached and sometimes don’t

Viewing 1 replies (of 1 total)
  • Plugin Support krzysztofskorupa

    (@krzysztofskorupa)


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

    function add_flexible_checkout_fields_attachments_to_vendor_email($attachments, $email_id, $order) {
    if ($email_id === 'new_order') {
    $uploaded_files = $order->get_meta('_billing_datei_upload', true);

    if (!empty($uploaded_files)) {
    if (is_string($uploaded_files)) {
    $uploaded_files = explode(',', $uploaded_files);
    }
    if (is_array($uploaded_files)) {
    foreach ($uploaded_files as $file) {
    $file_path = get_attached_file($file);
    if ($file_path && file_exists($file_path)) {
    $attachments[] = $file_path;
    }
    }
    } else {
    $file_path = get_attached_file($uploaded_files);
    if ($file_path && file_exists($file_path)) {
    $attachments[] = $file_path;
    }
    }
    }
    }

    return $attachments;
    }

    Hi,
    thank you very much for your contact.

    Can you please check if this code will work correctly?
    It differs slightly, but it takes into account the situation when HPOS is enabled on the site.

    Let us know if it works properly now.
    Greetings,

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.