How to Attach a Custom File to a WooCommerce Product

How to Attach a Custom File to a WooCommerce Product
On this page
  1. Why Attach Extra Files Beyond Product Images
  2. Step 1: Add a File Upload Field to the Product Editor
  3. Step 2: Display the Download Link on the Product Page
  4. Troubleshooting
  5. Frequently Asked Questions
  6. Conclusion

You can attach a custom file to a WooCommerce product — like a spec sheet, size guide, or manual — by adding a file upload field to the product editor, saving it as post meta, and linking it as a download on the front-end product page.

Why Attach Extra Files Beyond Product Images

  • Spec sheets and manuals reduce pre-sale questions for technical or complex products
  • Size guides can lower returns caused by sizing mismatches
  • Keeps supporting documents tied directly to the specific product they belong to
  • Different from WooCommerce’s built-in “Downloadable” product type, which is meant for the product being sold, not supporting docs

Step 1: Add a File Upload Field to the Product Editor

PHP
/** Add a "Spec Sheet" upload field to the Product Data General tab */
add_action( 'woocommerce_product_options_general_product_data', 'render_spec_sheet_upload_field' );

function render_spec_sheet_upload_field() {
    global $post;
    $existing_url = get_post_meta( $post->ID, 'spec_sheet_url', true );
    echo '<div class="options_group">';
    woocommerce_wp_text_input( array(
        'id'          => 'spec_sheet_url',
        'label'       => 'Spec Sheet URL',
        'value'       => $existing_url,
        'description' => 'Upload the file to Media Library and paste its URL here.',
    ) );
    echo '</div>';
}

/** Save the field */
add_action( 'woocommerce_process_product_meta', 'save_spec_sheet_upload_field' );

function save_spec_sheet_upload_field( $post_id ) {
    if ( isset( $_POST['spec_sheet_url'] ) ) {
        update_post_meta( $post_id, 'spec_sheet_url', esc_url_raw( $_POST['spec_sheet_url'] ) );
    }
}
PHP
/** Show a download link for the spec sheet, if one is set */
add_action( 'woocommerce_single_product_summary', 'display_spec_sheet_download_link', 25 );

function display_spec_sheet_download_link() {
    global $product;
    $spec_sheet_url = get_post_meta( $product->get_id(), 'spec_sheet_url', true );

    if ( $spec_sheet_url ) {
        echo '<p><a href="' . esc_url( $spec_sheet_url ) . '" target="_blank" class="spec-sheet-link">Download Spec Sheet (PDF)</a></p>';
    }
}
Attach a custom file to a WooCommerce product: the page before adding the code
Before
Attach a custom file to a WooCommerce product: the page after adding the code
After

Troubleshooting

Link shows but the file 404s

Confirm the file was fully uploaded to the Media Library and the copied URL points to the actual file, not the attachment page — copy the “File URL”, not the “Attachment Page URL”, from the media details panel.

Want to restrict the download to logged-in customers only

Wrap the display function in an is_user_logged_in() check, or better, use WooCommerce’s native downloadable product feature if access should be tied specifically to a completed purchase.

Frequently Asked Questions

Should I use this instead of WooCommerce’s Downloadable product type?

No — use the built-in Downloadable type when the file itself is what’s being sold. This approach is for supporting documents attached to a physical or standard product.

Can I attach more than one file per product?

Yes, repeat the pattern with a different meta key for each additional file (e.g. warranty_doc_url, size_guide_url).

Does this work for variable products?

Yes, since the field is saved against the parent product ID — all variations share the same attached file unless you build variation-specific logic separately.

Conclusion

A simple text field and two hooks are enough to attach a custom file to a WooCommerce product for spec sheets, manuals, or size guides. Keep it separate from WooCommerce’s own Downloadable product feature, which is meant for files that are the actual purchase.

See also How to Add File Upload for Product Personalization in WooCommerce. Then read How to Fix Sorry This File Type Is Not Permitted for WooCommerce Downloadable Products.

Prefer no code? All-in-One Utilities Woo Add-on adds over 50 WooCommerce features, so you can switch them on without code.

Leave a Reply

Schedule a call