Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

WC_API_Products::save_downloadable_files( WC_Product $product, array $downloads, int $deprecated )

Save downloadable files


Description Description


Parameters Parameters

$product

(Required)

$downloads

(Required)

$deprecated

(Required) Deprecated since 3.0.


Top ↑

Return Return

(WC_Product)


Top ↑

Source Source

File: includes/legacy/api/v2/class-wc-api-products.php

1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
private function save_downloadable_files( $product, $downloads, $deprecated = 0 ) {
    if ( $deprecated ) {
        wc_deprecated_argument( 'variation_id', '3.0', 'save_downloadable_files() does not require a variation_id anymore.' );
    }
 
    $files = array();
    foreach ( $downloads as $key => $file ) {
        if ( isset( $file['url'] ) ) {
            $file['file'] = $file['url'];
        }
 
        if ( empty( $file['file'] ) ) {
            continue;
        }
 
        $download = new WC_Product_Download();
        $download->set_id( ! empty( $file['id'] ) ? $file['id'] : wp_generate_uuid4() );
        $download->set_name( $file['name'] ? $file['name'] : wc_get_filename_from_url( $file['file'] ) );
        $download->set_file( apply_filters( 'woocommerce_file_download_path', $file['file'], $product, $key ) );
        $files[]  = $download;
    }
    $product->set_downloads( $files );
 
    return $product;
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.2 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.