admin管理员组

文章数量:1122846

I have many plugins that use filename field of the file of my WooCommerce downloadable product, to show the download button! WooCommerce also does this here to display the file name in the user panel:

woocommerce/templates/order/order-downloads.php

with:

echo '<a href="' . esc_url( $download['download_url'] ) . '" class="woocommerce-MyAccount-downloads-file button alt">' . esc_html( $download['download_name'] ) . '</a>';

I don't want to edit the filename field of all the products I also don't want to edit the codes of those plugins

Is there a way to symbolically and hypothetically change and set all filename? i think WooCommerce should to introduce the file name as I choose. For example, tell everyone file name of all file is "free download", not "ps-action.zip"

i think woocommerce handle this here:

woocommerce/includes/wc-user-functions.php line 656

        // Download name will be 'Product Name' for products with a single downloadable file, and 'Product Name - File X' for products with multiple files.
            $download_name = apply_filters(
                'woocommerce_downloadable_product_name',
                $download_file['name'],
                $_product,
                $result->download_id,
                $file_number
            );

            $downloads[] = array(
                'download_url'        => add_query_arg(
                    array(
                        'download_file' => $product_id,
                        'order'         => $result->order_key,
                        'email'         => rawurlencode( $result->user_email ),
                        'key'           => $result->download_id,
                    ),
                    home_url( '/' )
                ),
                'download_id'         => $result->download_id,
                'product_id'          => $_product->get_id(),
                'product_name'        => $_product->get_name(),
                'product_url'         => $_product->is_visible() ? $_product->get_permalink() : '', // Since 3.3.0.
                'download_name'       => $download_name,
                'order_id'            => $order->get_id(),
                'order_key'           => $order->get_order_key(),
                'downloads_remaining' => $result->downloads_remaining,
                'access_expires'      => $result->access_expires,
                'file'                => array(
                    'name' => $download_file->get_name(),
                    'file' => $download_file->get_file(),
                ),
            );

            $file_number++;
        }
    }

    return apply_filters( 'woocommerce_customer_available_downloads', $downloads, $customer_id );
}

Maybe we can apply a filter in this way to display our text (just display it, not insert it into the filename field)

本文标签: Changing the all filename field of WooCommerce products