WooCommerce Product – Custom data field not saving

Question

Heyo! I’m working on adding a file upload in a custom tab of my WooCommerce products. I have a custom tab with a file input. I’m trying to save the file for use with another option, but when product_visualizer_save_data is called, nothing is in $_FILES.

function product_visualizer_add_data() {
    // add a section to WooCommerce's product metadata for uploading the file
    require 'custom_data_tab.php';
}

function product_visualizer_save_data($postid) {
    $upload = null;
    if (isset($_FILES['product_data_file'])) {
        $upload = wp_handle_upload($_FILES['product_data_file']);
        if (is_wp_error($upload)) {
            // error!
        } else {
            // uploaded
        }
    }
    die(var_dump($_FILES)); // empty
}

add_action('woocommerce_product_data_panels', 'product_visualizer_add_data');
add_action('woocommerce_process_product_meta', 'product_visualizer_save_data');

I’m thinking the file upload being missing has to do with WooCommerce’s <form> not having enctype="multipart/form-data", but I couldn’t find any hooks or pages related to it.

Could it potentially be a problem with me using PHP’s require?

0
Pat 5 months 2020-12-22T04:10:22-05:00 0 Answers 3 views 0

Leave an answer

Browse
Browse